inheritance

T

Tony Johansson

Hello!

If you have a class declaration like class Test below will number be public
or private. I mean if you don't specify explicitly what is the default
access.
And in the inheritance declaration below where we have class Derive inherit
from class Base what type of inheritance is it there public or private?

class Test
{
int number;

};

class Derive : Base
{

};

//Tony
 
K

Kristo

Tony said:
Hello!

If you have a class declaration like class Test below will number be public
or private. I mean if you don't specify explicitly what is the default
access.
And in the inheritance declaration below where we have class Derive inherit
from class Base what type of inheritance is it there public or private?

class Test
{
int number;

};

class Derive : Base
{

};

Private in both cases. If you had structs, it would be public in both
cases. But why does it matter? You shouldn't omit access specifiers
because it creates ambiguity. I had to dig through the standard for
five minutes to answer your question. People reading your code
shouldn't have to do that. Just say what you mean and be done with it.

Kristo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top