I have some static const strings as private members of my C++ class. I am aware of the declaration in .h and definition (and initialization) in .cpp practice. In the class constructor I invoke a function that uses these static strings. Surprisingly when in constructor, the strings remain uninitialized (empty strings) which is creating a problem.
Can somebody point out what might be going wrong here? I work with such usage of static const strings all the time but never ran into such situations.
Update: m_data remains empty in utility(). I have a Test class object as a private member of another class.
Here is a kind of code I am 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
}