1

I'm working on c++, following is my template class:

namespace My{    
template<class config>
class BasicValue
{
public:
    enum Type
    {
        NULL_TYPE = 0,
        OBJECT_TYPE,
        ARRAY_TYPE,
        STRING_TYPE,
        BOOL_TYPE,
        INT_TYPE,
        REAL_TYPE,
    }; // Type
};// BasicValue

}// My

Now, Im accessing this "Type" enum from another .cpp file. Im getting following compilation error for all enum types:

error: ‘STRING_TYPE’ was not declared in this scope

How I can use this enum outside the "My" namespace?

Following is the code usage, Im using the enum value in switch case:

void printValue(const Value& val, int space)
{    
    int sp = space;
    switch(val.type())
    {
        case STRING_TYPE:
            break;
        case BOOL_TYPE:
            break;
        case INT_TYPE:
            break;
        case REAL_TYPE:
            break;
        default:
            exit(-1);
    }
}
Torbilicious
  • 467
  • 1
  • 4
  • 17
balaji
  • 1,075
  • 3
  • 12
  • 26

1 Answers1

3

Something like

My::BasicValue<int>::Type t;           // get an instance of the type
....
t = My::BasicValue<int>::STRING_TYPE;  // get a value

but this assumes you fix all the syntax errors in the code, as in this example..

juanchopanza
  • 223,364
  • 34
  • 402
  • 480