Making private member inheritable or Accessible in c++



Making private member inheritable or Accessible in c++



  GNU nano 2.9.1                                                                                                      test.cpp                                                                                                      Modified  

/********************************************************************************************************
*************Designed and Developed by V2Geeks******************************************
********************************************************************************************************/

 // Example of  Making private member inheritable
 #include<iostream.h>
 #include<conio.h>
class A                                 // base class
 {
 public:
        void display()
        {
                cout<<"Hello from A \n";
        }
  };
 class B :private A
 {
         public:
        void  show()   // now we can call private member in public function
        {
                display();
        }
 };
void main()
        {
                B objB;
                clrscr();
                //  objB.display();       //ERROR:display() is private so can not be called.
                objB.show();               //calling of private function display() indirectly
        getch();
        }
Reactions: