Static import in C ++ 11 (e.g. enum class)

My use of the 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, it gets very dirty.

Is it possible to somehow import the enumeration values so that I can write:

matrix* m = new matrix(ADD);

The same goes for nested classes - can I import them?

+5
source share
1 answer

No , this is not possible.

You cannot omit the part operation_typebecause you made it a cloud enumeration (and this is what is enumerated in the scope). If you want to avoid this, you must make it unoccupied enum(keyword removal class).

, matrix using, matrix . , 7.3.3/7 ++ 11:

- .

+4

All Articles