I’m looking to do something like the following:
class Whatever {
public:
enum PhysicalObjectType {
STATIC_MISC_OBJECT,
DYNAMIC_MISC_OBJECT,
STATIC_MISC_OBJECT_WALKABLE,
DYNAMIC_MISC_OBJECT_WALKABLE,
STATIC_MISC_OBJECT_KILL,
DYNAMIC_MISC_OBJECT_KILL,
STATIC_MISC_OBJECT_BREAK,
DYNAMIC_MISC_OBJECT_BREAK,
BOUNDARY,
BOUNDARY_GROUND,
PERMANENT_JOINT,
MOUSE_JOINT
};
};
And then a method that will retrieve a type based on the above code outside of the class. So lets say within another class I have an instance of Whatever and I call getType() on myWhateverInstance and do a comparison to determine what type it is, like so:
if( myWhateverInstance.getType() == STATIC_MISC_OBJECT ) {
}else ...
That however, is not working. Basically no matter how I try and resolve them, I cannot access any values within the enum outside of the class. What noob mistake am I making here? (Note the specific errors I’m getting are not declared in scope or XX is not a valid namespace or class, etc).
When accessing enumerators that are members of a class, you have to qualify their names with the class’s name. So the enumerators are
Whatever::STATIC_MISC_OBJECTand so forth.This is only necessary when accessing the enumerator from outside of the class. From within the class’s scope, you can simply use the base name.