I have a class with some internal state (let's say) color and texture. Each has a limited number of valid values, so I'm using good old type-safe enums, and because each enum includes a None value, I'm using the new C++/11 syntax; enum class, so the enumerands will be scoped to the enum type and not the containing class:
The Color and Texture types are implementation details, so I'd prefer not to make them public, but making them private prevents me from accessing any of the enumerands.
class MyClass
{
private:
enum class Color {
None, Red, Green
} _color;
enum class Texture {
None, Smooth, Rough
} _texture;
public:
MyClass()
: _color(Color::Green)
---------- <== ERROR: Member is inaccessible
, _texture(Texture::Rough)
-------------- <== ERROR: Member is inaccessible
{
}
};
If Color was a private nested class definition, I could include a 'friend class MyClass' declaration within the inner class, but no such syntax seems to be valid for an enum.
Can someone explain why this isn't working, and how it's supposed to be done?
Aucun commentaire:
Enregistrer un commentaire