I have a class which contains an enum which I reference when I overload an operator for that class. However, it appears that I must prefix ClassName:: whenever I reference the enum:
[code=cpp]
// example.h
class ExampleClass
{
public:
enum WeekDay {SAT, SUN, MON, TUE, WED, THU, FRI};
};
// example.cpp
#include "example.h"
ostream& operator << (ostream& stm, ExampleClass const & ex)
{
WeekDay d = SAT; // error!
ExampleClass::W eekDay d = ExampleClass::S AT; // works
return stm;
}
[/code]
Is there anyway to avoid this so that I can use the shorter first syntax, like we do with the "using namespace std;" statement to avoid prefixing std:: everywhere (which won't work here because Example is not a namespace)
[code=cpp]
// example.h
class ExampleClass
{
public:
enum WeekDay {SAT, SUN, MON, TUE, WED, THU, FRI};
};
// example.cpp
#include "example.h"
ostream& operator << (ostream& stm, ExampleClass const & ex)
{
WeekDay d = SAT; // error!
ExampleClass::W eekDay d = ExampleClass::S AT; // works
return stm;
}
[/code]
Is there anyway to avoid this so that I can use the shorter first syntax, like we do with the "using namespace std;" statement to avoid prefixing std:: everywhere (which won't work here because Example is not a namespace)
Comment