Reputation: 9212
I have used enum variable as static but not defined outside the class.
enum log_level_e
{
error=1,
warning,
debug,
trace
};
class Logger
{
private:
static mutex logger_mutex;
Logger() {}
~Logger() {}
Logger (const Logger& source);
Logger& operator== (const Logger& source);
static log_level_e loglevel;
// functions and all
};
Ideally, it should give a link time error, but it's working fine without error. Why is it so? I am using a C++11 compiler.
Upvotes: 1
Views: 146
Reputation: 9097
Because nobody is using it and the linker does not attempt to look for it. This gives you the "desired" error
class Logger
{
public:
Logger() {
loglevel = warning;
}
~Logger() {}
private:
Logger (const Logger& source);
Logger& operator== (const Logger& source);
static log_level_e loglevel;
// functions and all
};
Upvotes: 4