Alan
Alan

Reputation: 2129

C++ inheritance public and private?

Is it possible to inherit both or all parts of a class (other than private) in C++?

class A {
}


clas B : ...? { }

Upvotes: 0

Views: 721

Answers (2)

Bruce
Bruce

Reputation: 2310

If you could inherit private members, then all you would have to do to access something private would be to inherit items from a parent class.

Upvotes: 1

casablanca
casablanca

Reputation: 70731

If you're asking whether you can make private members visible to derived classes, the answer is no - that's why they are private. Use protected members in the base class if you want derived classes to be able to access them.

Upvotes: 8

Related Questions