开发者

C++'s default inheritance access specifier? [duplicate]

This question already has answers here: 开发者_运维技巧 Default class inheritance access (4 answers) Closed 3 years ago.

I have some legacy code that I have to wrap, and I have come across this declaration:

class Foo : Bar
{
    // ...
};

This seems to compile under GCC. I know it's bad, but I can't change it. My question is, if no inheritance access specifier is present, how does the C++ compiler handle it?


For classes, the default is private.

For structs, the default is public.


BTW, it is not called access modifier. It is called access specifier

$11.2/2 - "In the absence of an access-specifier for a base class, public is assumed when the derived class is defined with the class-key struct and private is assumed when the class is defined with the class-key class."

In your context, 'Bar' is a private base class of 'Foo'


It's private.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜