[英]MSVC claims public member is inaccessible
我有一个带有公共枚举成员的结构:
namespace A {
struct Events {
enum CUES { CLEAR, DATA, ERROR };
virtual void Event(CUES) = 0;
protected:
~Events() {}
};
}
当我尝试从另一个类访问CLEAR
,编译器会产生一个错误,表明它无法访问。
这是代码和错误:
namespace B {
class Base: A::Events{
void Event(Events::CUES){}
protected:
Events::CUES lastCue;
};
class Impl: public Base {
bool test(){
return (lastCue == A::Events::CLEAR);
}
};
}
somefile(19): error C2247: 'A::Events::CLEAR' not accessible because 'B::Base' uses 'private' to inherit from 'A::Events'
somefile(3): note: see declaration of 'A::Events::CLEAR'
如何访问公共枚举?
更新: gcc
似乎编译这个没有任何问题。
我想出的解决方案是通过全局命名空间更改访问路径:
namespace B {
class Impl: public Base {
bool test(){
return (lastCue == ::A::Events::CLEAR);
} // ^^
};
}
这避免了对Base
任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.