Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Sep 10, 2001

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 <iostream.h>
class base
{
   public:
      int a;
      int b;
      base()
      {
        a=10;
        b=20;
      }
      void show_a(void)
      {
       cout<<a<<endl;
      }

      void show_b(void)
      {
       cout<<b<<endl;
      }
 };

class derived:private base
{
    public:
          base::a;
          base::show_a;
};

int main(void)
{
     derived d1;
      d1.show_a();
      d1.a=200;
      d1.show_a();
}

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.
Narla Rajashekar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date