如何连接现有类
我有一个类,里面有一个枚举“AT_Color”:
class K_DxfDwgColor {
enum AT_Color { Normal = 0, ByLayer = 1, ByBlock = 2 };
COLORREF m_crColor = 0;
AT_Color m_atColor = AT_Color::Normal;
public:
K_DxfDwgColor(COLORREF pkColorref) :m_crColor(pkColorref) {};
K_DxfDwgColor(K_DxfDwgColor::AT_Color paColor):m_atColor(paColor){};
OdCmColor colorClone;
OdCmColor SetLayerColor(bool pbDefaultForegroundColor, bool pbByLayer, bool pbIsSolidFill);
COLORREF GetColor(){ return m_crColor;}
AT_Color GetType() { return m_atColor;}
};
该枚举在类中被声明为私有,这意味着它不能从主类访问。 现在,我们要为此类声明一个对象,并使用获取 AT_Color 的构造函数。
K_DxfDwgColor colorDefiner(K_DxfDwgColor::ByBlock);
每次我以这种方式声明对象时,都会收到一条错误消息,指出枚举无法访问。有人可以告诉我如何正确声明吗?
提前致谢
I have this Class that have an enum "AT_Color" inside:
class K_DxfDwgColor {
enum AT_Color { Normal = 0, ByLayer = 1, ByBlock = 2 };
COLORREF m_crColor = 0;
AT_Color m_atColor = AT_Color::Normal;
public:
K_DxfDwgColor(COLORREF pkColorref) :m_crColor(pkColorref) {};
K_DxfDwgColor(K_DxfDwgColor::AT_Color paColor):m_atColor(paColor){};
OdCmColor colorClone;
OdCmColor SetLayerColor(bool pbDefaultForegroundColor, bool pbByLayer, bool pbIsSolidFill);
COLORREF GetColor(){ return m_crColor;}
AT_Color GetType() { return m_atColor;}
};
The enum is declared private in the class, which means it is not accessiblefrom the main.
Now, we want to declare an object for this class and use the constructor which gets an AT_Color.
K_DxfDwgColor colorDefiner(K_DxfDwgColor::ByBlock);
Every time I declare my object this way, I get an error message that the enum is inaccessible. Can someone show me how to declare it correctly?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将枚举移到类之外,需要调用方知道:
Move the enum outside of the class, it is necessary to be known from the calling party: