简体   繁体   中英

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 : ...? { }

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.

如果您可以继承私有成员,那么访问私有对象所需要做的就是从父类继承项目。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM