I want to compare two enums of same type with "<=" operator but it gives error.
// Logger.h
namespace MT
{
class Logger
{
public:
enum LogLevel
{
LogLevel_None = 0,
LogLevel_Error = 1,
LogLevel_Warning = 2,
LogLevel_Info = 3,
LogLevel_Debug = 4
};
void log(LogLevel targetLevel,std::string time = "",std::string className = "", std::string functionName = "", std::string message = "");
private:
LogLevel level;
};
}
// Logger.cpp
void MT::Logger::log(LogLevel targetLevel,std::string time, std::string className, std::string functionName, std::string message)
{
.
.
.
if(targetLevel <= level) // THIS LINE GIVES ERROR
.
.
.
}
The error is:
error C2676: binary '<=' : 'MT::Logger::LogLevel' does not define this operator or a conversion to a type acceptable to the predefined operator
Why do I get this error? Isn't it safe to compare enums with relational operators? Note that when I static_cast to enums in error line, it gives another compiler error.
Please, help me to compare enums.
EDIT: The problem is SOLVED, however; I cannot explain how it did. I got this error when I was trying to modify my existing Logger class to singleton so now, I finished this modification and the error disappeared. Anyway, thank you for your consideration and @Bo Persson let's make peace.