I have some static constant strings as private members of my C ++ class. I know the declaration in .h and the definition (and initialization) in .cpp practice. In the class constructor, I call a function that uses these static lines. Surprisingly, in the constructor, strings remain uninitialized (empty strings), which creates a problem.
Can someone point out what might be wrong here? I have been working with this use of static constant strings all the time, but have never come across such situations.
Update: m_data remains empty in utility (). I have an object of class Test as a private member of another class.
Here is the code I'm using:
// Test.h class Test { public: Test(); private: void utility(); static const std::string m_data; }; // Test.cpp const std::string Test::m_data = "Data"; Test::Test() { utility(); } void Test::utility() { //use m_data here }
AG
source share