Inheritance for private member | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Inheritance for private member

As far as I know , private embers of base class are not accessible in derived class... I heard (very first time) that private member are inherited , but those are not accessible... is this true? if those are inherited but not accessible, then what is the usecase of this scenario?

30th May 2018, 8:06 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 2
yes it is true thing private members are inherited. here is the code of verification. I have verified by printing the size of object. https://code.sololearn.com/cbOD6FCQxDi8/?ref=app also private members arenot accessible in derived class. it is programmers responsibility to design a robust code and accordingly put a decision to take private data members.
30th May 2018, 9:03 AM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar
+ 2
Ketan Lalcheta man a big salute to you. You have earned 48k xp in c++.
30th May 2018, 9:10 AM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar
+ 1
great to know this.... never thought about this anytime before...
30th May 2018, 9:08 AM
Ketan Lalcheta
Ketan Lalcheta - avatar