// oop.cpp : Defines the entry point for the console application. // #include using namespace std; class A { protected: int a; public: int x; A(int b) { x = 1; cout << "Parent Constructor : " << endl; a = b;} virtual void show () {x = 1; cout << "Parent: "; cout << a << endl;} //class with pure virtual function is abstract and can't be instantiated //virtual void show()=0; //pure virtual function void myfun() { cout << "Parent My Function";} }; class B : public A{ private: int a; int b; public: int x; B(int a, int b); void show(){x = 0; cout << "Child: "; cout << a << endl;} //friend function can access all members of the class inside which it is defined friend void f(); void myfun(){cout << "Child My Function";} }; B::B(int a, int b):A(b) { x = 0; this->a = a; this->b = b; } void f() { B b(1, 1); b.b = 10; cout << "Friend" << endl; cout << "Value of b is " << b.b << endl; } int main() { B b(1, 2); f(); A *a; //example of polymorphism a = &b; a->show(); //if the parent function is not defined as virtual //every call to the function will call parent version a->myfun(); cout << a->x << endl; //member variables of parents are always accessed. A c(2); a = &c; a->myfun(); a->show(); cout << a->x <