【发布时间】:2015-04-12 11:56:03
【问题描述】:
鉴于下面的代码,如果基类中的函数通过继承保护,我们可以访问基类的私有数据。我的问题是,如果基类中的所有方法也都设置为私有,我们有什么方法可以访问私有数据?
class Base
{
int i;
protected:
void set(int data){
i = data;
}
int get(){
return i;
}
};
class derive: Base{
public:
void change(int x){
set(x);
cout<<get()<<endl;
}
};
int main()
{
derive b;
b.change(3);
return 0;
}
【问题讨论】:
-
呃,不,因为没有其他人可以打电话给他们。
标签: c++ inheritance private