【发布时间】:2016-12-12 01:44:51
【问题描述】:
我的问题是为什么b.getmultiply(); 不会导致编译错误?
B 类是从 A 类私有继承的,x 和 y 是 A 类的成员。
class A {
public:
int x;
int y;
void set(int a, int b) { x = a; y =b;}
};
class B : private A{
public:
int getmultiply (void){
return x*y;}
};
int main(void)
{
B b;
//b.set(3,4); // this will cause compilation error
cout << b.getmultiply(); // why this will not??
return 0;
}
【问题讨论】:
标签: c++ inheritance private