Home > Software design >  How to interface an existing class
How to interface an existing class

Time:02-25

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

CodePudding user response:

Move the enum outside of the class, it is necessary to be known from the calling party:

enum AT_Color { Normal = 0, ByLayer = 1, ByBlock = 2 };

class K_DxfDwgColor {
public:
    K_DxfDwgColor(AT_Color paColor):m_atColor(paColor){};
}
  • Related