我想从基类访问子类中的数据成员。我不知道有没有可能。如果可能的话,请告诉我该怎么做。
class a {
void sample(){
//i want to use the ptr value here
}
}
class b: public a{
int *ptr;
b(int *_ptr){ptr=_ptr;}
}
有了现有的代码,这是不可能的。
获得所需内容的最佳方法可能是使classptr
成为protected
成员a
,以便继承自a
(例如b
)的所有类都可以访问它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句