문제

My usage of enum class (VS2012):

class matrix {
public:
    enum class operation_type {ADD, MULT};
    matrix(operation_type op);
...
}

and in another fragment I use

matrix* m = new matrix(matrix::operation_type::ADD);

If the names are long, this becomes very messy.

Is it possible to somehow import the enum values so that I could write:

matrix* m = new matrix(ADD);

The same regards nested classes - can I import them?

도움이 되었습니까?

해결책

No, it is not possible.

You cannot omit the operation_type part, because you have made this a scoped enumeration (and that is what scoped enumeration are all about). If you want to avoid it, you have to make it an unscoped enum (removing the class keyword).

Besides, outside of matrix you cannot import a member name through a using declaration as if matrix was a namespace. Moreover, per Paragraph 7.3.3/7 of the C++11 Standard:

A using-declaration shall not name a scoped enumerator.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top