提问人:Mr. Developerdude 提问时间:3/4/2023 更新时间:3/4/2023 访问量:66
“methodX() is a protected member of MyClass”(method X() is a protected member of MyClass“错误,该错误在扩展 MyClass 的类中
"methodX() is a protected member of MyClass" error inside class that extends MyClass
问:
在以下代码中:
struct A{
protected:
virtual void IAmProtected() = 0;
};
struct B: public A{
private:
A * a;
protected:
void IAmProtected() override;
public:
void doSomething(){
a->IAmProtected(); // ERROR: 'IAmProtected' is a protected member of 'A'
}
};
我得到“IAmProtected”是“A”的受保护成员,我觉得这很奇怪,因为 B 实际上是 A 的扩展。
我想知道
- 为什么会这样?
- 我怎样才能防止这种情况发生?
答: 暂无答案
评论
protected
a->IAmProtected();
B
B
A
A*
B
public
A::IamProtected()