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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With