dcsimg
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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