How to Make a Private Member Public

How to Make a Private Member Public

You can make a privately inherited member public by specifying its access modifier in the derived class. For example:

 #include class base{   public:      int a;      int b;      base()      {        a=10;        b=20;      }      void show_a(void)      {       cout

In the above example, the class named base is privately inherited into the class derived, making the variables a, b, and member functions show_a(), show_b() private, but making a declaration of a and show_a() in the public section of derived, making them public again.


Share the Post: