Skip to content

Instantly share code, notes, and snippets.

@dibakarsutradhar
Created September 5, 2018 17:03
Show Gist options
  • Save dibakarsutradhar/991632f49dd474afe4bdea0e6e85d016 to your computer and use it in GitHub Desktop.
Save dibakarsutradhar/991632f49dd474afe4bdea0e6e85d016 to your computer and use it in GitHub Desktop.
// C++ Inheritance
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
// Base Class
class Parent{
public:
int id_p;
};
// Sub Class inhertiating from Base Class
class Child : public Parent {
public:
int id_c;
};
// Main Function
int main() {
Child obj1;
// An object of class child has all data members and member functions of class Parent
obj1.id_c = 10;
obj1.id_p = 20;
cout << "Child id is: " << obj1.id_c << endl;
cout << "Parent id is: " << obj1.id_p << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment