In my class I defined an enum like this:
class myClass
{
public:
enum access {
forL,
forM,
forA
};
typedef access AccessType;
AccessType aType;
};
Later in defined an object like this:
myClass ob;
ob->aType = 0;
However I get this error:
error: invalid conversion from 'int' to 'myClass::AccessType {aka myClass::access}' [-fpermissive]
Don’t enum fields map to integers?
No, they are stored as integers but they are distinct types (e.g. you can even overload based on the enum type). You must convert explicitly:
or ever better write the corresponding named value of the enum:
Or perhaps if you want to use the enum just as a set of integer constants, change the type of the field:
Conversion from enum to int is implicit.