Struct and class and inheritance (C ++)

Could you provide me if all access specifiers (including inheritance) structare equal public?

In other words: equal?
class C: public B, public A { public:
    C():A(1),B(2){}
    //...
};

and

struct C: B, A {
    C():A(1),B(2){}
    //...
};
+5
source share
3 answers

From C ++ standard , 11.2.2, p. 208:

In the absence of an access specifier for the base class, public is considered when the declared derived class is declared as struct and private if the class is declared as a class.

So, you are right: when a derived class is struct, it inherits other classes as publicif you did not specify otherwise.

+2
source

Yes, they are all publicly available.

struct A : B {
  C c;
  void foo() const {}
}

equivalently

struct A : public B {
 public:
  C c;
  void foo() const {}
}

For members, this is stated in §11:

, , . , struct union keywords, .

§11.2:

public , private, .

++ 11.

+7

From the standard C ++ 11 ( project N3242 )

11.2 Availability of base classes and base classes

2 In the absence of an access specifier for the base class, public is assumed when the derived class is defined using the structure of the key class and private is accepted when the class is defined by the class key class.

+2
source

All Articles