Ric*_*ves 0 c++ inheritance private
标题是:
课程如下:
class A
{
public:
int a;
int b;
int c;
function1();
function2();
}
Run Code Online (Sandbox Code Playgroud)
和B类扩展A,如何将A中的所有变量公开?
class B : private A
{
public:
int a; //How to turn this public from A
int b; //How to turn this public from A
int c; //How to turn this public from A
}
Run Code Online (Sandbox Code Playgroud)
将公共数据和私有基类的成员公开为派生类中的公共数据是一个坏主意.但是,如果必须,您可以使用:
class B : private A
{
public:
using A::a;
using A::b;
using A::c;
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
85 次 |
最近记录: |