views:

232

answers:

2

Hi,

I want to initialize two static data members. See the two files

//Logger.h   

 class Logger{

    public:
        static LoggerConcrete error;
        static LoggerConcrete write;
    };

and

//Logger.cpp

Logger::error = LoggerConcrete(LOG_DEBUG);
Logger::write = LoggerConcrete(LOG_DEBUG);

The initilization of the two static members in Logger.cpp doesn't work. I get the following compiler (g++) error:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Logger.d" -MT"Logger.d" -o"Logger.o" "../Logger.cpp" ../Logger.cpp:13: error: expected constructor, destructor, or type conversion before '=' token ../Logger.cpp:14: error: expected constructor, destructor, or type conversion before '=' token

I want to use Logger::write and Logger::error in each class in which I include Logger.h. How do I have to initialize these two members?

+8  A: 

You need to specify the type:

LoggerConcrete Logger::error = LoggerConcrete(LOG_DEBUG);
LoggerConcrete Logger::write = LoggerConcrete(LOG_DEBUG);
Shog9
yuup, I forgot. thanks
Maus
+4  A: 

You can also use this syntax, a little more concise:

LoggerConcrete Logger::error(LOG_DEBUG);
LoggerConcrete Logger::write(LOG_DEBUG);
AshleysBrain