We know that private members are not inherited whenever we inherit a base class to get a derived class, but is it possible for derived class member functions to access the private members of the base class?
+3
A:
Private members are inherited, but they are not accessible. They are "private" for a reason. However, if your derived class needs to access them, it should be declared a friend to the base class.
Hosam Aly
2010-07-11 08:14:19
can i know the reason why they can't be accessed
anurag18294
2010-07-11 08:17:46
Because they were meant to be used by the base class members only, as decided by its designer. If the designer wanted derived classes to be able to use or access these members, he could have declared them protected.
Hosam Aly
2010-07-11 08:34:23
+2
A:
Private members of the base class are inherited by the derived class, but are not (directly) accessible to it. They may still be accessed by protected and public members of the base class. As Hosam Aly says above one could access base class members by making derived class functions friends of the base class, or by turning the private members of the base class into protected members of the base class, whichever is preferable.
Brian Hooper
2010-07-11 08:17:27