+ 1

How can we access private members of base class through sub class when inhertance is done??

26th Aug 2016, 5:42 PM
Sunitha Ganti
Sunitha Ganti - avatar
3 Antworten
+ 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; };
26th Aug 2016, 6:09 PM
Zen
Zen - avatar
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.
26th Aug 2016, 10:32 PM
Stefan
Stefan - avatar
0
ok got it tq
27th Aug 2016, 12:37 AM
Sunitha Ganti
Sunitha Ganti - avatar