Enum in a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koregu
    New Member
    • Oct 2006
    • 1

    Enum in a class

    Hi all

    I have code that looks like this:

    //// MyThing.h
    #include <string>

    using std::string;

    class MyThing
    {
    public:
    enum Value
    {
    FIRST,
    SECOND,
    THIRD,
    COUNT
    }

    static Value lookup(string &stringFromFile );
    private:
    ...
    };
    ////

    In another file I have:

    //// UsingMyThing.cc
    #include "MyThing.h"

    void Foo(MyThing::Va lue bar)
    {
    switch(bar)
    {
    case FIRST:
    // do something neat
    break;
    case SECOND:
    // do something neat
    break;
    case THIRD:
    //die
    default:
    break;
    }
    }
    ////

    My problem is that for some reason, my compiler's telling me that it's never seen FIRST, SECOND, or THIRD. What is the reason for this? Would I get an error like this if I exposed a similar enum with values of the same name?...

    -koregu
  • dariophoenix
    New Member
    • Oct 2006
    • 34

    #2
    Try referring to those constants with the scope operator, for example: MyThing::FIRST

    Comment

    Working...