Q:

how to initialize a static member in cpp file only situation via a

I have a class in a cpp file. There is no header file in my case:
class MyClassATest
{
     static Logging &logger = Logging::getInstance();

     static void testMethodA()
     {
          logger.logDebug(....);

     }

};

I tried several different ways try to make the first statement works:
constexpr static Logging &logger = Logging::getInstance();
static Logging const &logger = Logging::getInstance();
constexpr static Logging const &logger = Logging::getInstance();

Is there a way to initialize that logger variable in my case?
EDIT:
Following are the results in different cases:
error: field initializer is not constant
         constexpr const static Logging &logger = Logging::getInstance();

error: field initializer is not constant
         constexpr static const BMLogging &logger = BMLogging::getInstance();

error: field initializer is not constant
         constexpr static BMLogging const &logger = BMLogging::getInstance();

error: field initializer is not constant
         constexpr static BMLogging &logger = BMLogging::getInstance();

A:

You can initialize it outside the class, like this:
// This goes in your CPP file at any point after the class declaration
Logging& MyClassATest::logger(Logging::getInstance());

Alternatively, you could put initialization in a static member function:
static Logging& logger() {
    // Make a function-static variable instead of a class-static one
    static Logging &loggerInstance(Logging::getInstance());
    return loggerInstance;
}

