While writing my initial question, if this is even possible, I stumbled about the question static constexpr member of same type as class being defined, which quite clearly answered that my clean solution is not possible with C++11.
But then I came up with this code which is quite close to the original poster and I want to achieve:
class MyEnum
{
public:
constexpr MyEnum() : m_null(true), m_value(0) { }
constexpr MyEnum(const unsigned int v) : m_null(false), m_value(v) { }
constexpr operator unsigned int() const { return m_value; }
static constexpr const MyEnum one() { return MyEnum(1); }
private:
bool m_null;
unsigned int m_value;
};
So I'm rephrasing my question: Why does the solution for one
compile and can be used as you would expect it but the following solutions give errors about using an incomplete class?
class MyEnum
{
public:
// snip...
static constexpr const MyEnum two = MyEnum(2);
static constexpr const MyEnum three = 3;
// snip...
}