4

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?

Peter G.
  • 14,786
  • 7
  • 57
  • 75
Ross Light
  • 4,769
  • 1
  • 26
  • 37

3 Answers3

10

For classes, the default is private.

For structs, the default is public.

Justin Ardini
  • 9,768
  • 2
  • 39
  • 46
9

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'

Chubsdad
  • 24,777
  • 4
  • 73
  • 129
1

It's private.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789