If a c++ application is organised in following manner
//file1.cpp
static Y sgObj = X::getInitObject(0); //declared in file scope
//file2.cpp
namespace{
int getInitValue()
{
static int val = Y::sObj.initVal();
return val;
}
}
namespace X{
Y getInitObject(int initVal)
{
if(initVal < getInitValue())
{
cout << "Print some log message" << endl;
}
return Y::initMethod(initVal);
}
}
//file.h
//This class is shipped as static and dynamic library, and application is supposed to link
//them in their executable based on their need
class Y{
public:
int initVal();
static Y initMethod(int val);
static Y sObj;
};
Assuming all the necessary header files are included and we are able to create the executable for this application, does it have initialization issue with the way I am creating the object in file1.cpp when:
- statically vs
- dynamically linking with the library(corresponding to implementation of class Y) for creating the object sgObj.
Given the class Y's implementation is not exposed to application, we can't change the way its static member sObj is created.
Does it have anything to do with platform / compiler being used?