Reputation: 1701
I'm adding a enum type to the very few bits of C++ I've learnt so far, but having trouble to set it...Am i missing some fundamentals?
class Rectangle
{
public:
Rectangle();
~Rectangle();
enum rectangle_directions_t {R_LEFT = 0, R_DOWN = 1, R_RIGHT= 2, R_UP = 3, R_NONE = 4};
void setRect(rectangle_directions_t rec_dir) {rectangle_direction = rec_dir;}
private:
rectangle_directions_t rectangle_direction;
};
int main()
{
Rectangle pRect;
pRect.setRect(R_LEFT);
}
Can you not just set a variable of an enum type like any other type? Or am i missing something simple? The error I get is during the "set" in main which says R_LEFT is undefined. Which is odd because I don't usually declare an "int" first if I want to pass it to a method...
Upvotes: 2
Views: 66
Reputation: 110658
The enumeration is defined within your class Rectangle
. You need to qualify R_LEFT
:
pRect.setRect(Rectangle::R_LEFT);
Upvotes: 8