如果我们重新定义数据成员,类的实现会发生什么变化? 例如,假设我们有:
class foo {
public:
int a;
char *b;
};
...
class bar : public foo {
public:
float c;
int b;
};
条形对象的表示是否包含一个或两个 b 字段?如果有两个,它们是都可以访问,还是只有一个?在什么情况下?
最佳答案
它包含两个,但其中一个叫做 foo::b
int main() {
bar x;
x.b = 0; // access bar::b
x.foo::b = 0; // access foo::b
}
关于c++ - 重定义数据成员时类的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5699044/