Click here to Skip to main content
15,662,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends. i have a question
if we don't define the kind of inheritance(public or private)
by default is the inheritance private?
for example if i write
class A
class B:A

is similar to
class A
class B:private A

is it true?
please help me. thanks

1 solution

Just like with unspecified member of a class, if you do not specify the access when you declare the inheritance it defaults to private.

So yes, your two examples are equivalent.
I'd personally prefer to see the latter form though, just as I prefer to see the access specified for members of a class.
Share this answer
sara74 21-Jun-14 1:58am    
ok. thanks my friend
OriginalGriff 21-Jun-14 2:10am    
You're welcome!
Joren Heit 22-Jun-14 11:49am    
Sidenote: when applying inheritance to structs, the default is public. Of course you can derive a struct from a class and vice versa, in which case the default depends on the type inherited from.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900