+ 1
How can we access private members of base class through sub class when inhertance is done??
3 Réponses
+ 2
The simplest way is to declare the private members of the base class as protected instead.
class Base{
protected:
...
}
If you really need the members private, you can otherwise declare the derived class as a friend of the base class in the base class definition.
class Base{
friend class Derived;
};
0
Private scope is *especially designed* to prevent access from any other entity than the class and it's instances. If you want to access a member better use protected scope as already was pointed out.
0
ok got it tq