Default class inheritance access

From standard docs, 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.

So, for structs the default is public and for classes, the default is private

Examples from the standard docs itself,

class D3 : B { / ... / }; // B private by default

struct D6 : B { / ... / }; // B public by default

Leave a Comment