To preface, I do not have a complete minimum functional example here to define the factory because I don't have access to the definitions of the dynamic library I'm using.
What I'm looking for right now is suggestions for reading, unless my issue is clearly a general one and doesn't require knowledge of the function definitions to explain.
Suppose we have some variation of a factory pattern which allows the following to compile and operate as intended, per the documentation that came with the DLL:
int main(){
std::cout << "Start" << std::endl;
Base* ptr = Base::Create();
ptr->ConcreteMemberDoSomething();
std::cout << "End" << std::endl;
}
With output:
Start
/-- Concrete Member... Output --/
End
With that in mind, why might this compile but (consistently) cause the program to hang indefinitely when run?:
class Init{
public:
Base* ptr;
Init(){
std::cout << "Ctor start" << std::endl;
ptr = Base::Create();
std::cout << "Ctor end" << std::endl;
};
~Init(){
std::cout << "Dtor" << std::endl;
};
}
Init obj;
int main(){
std::cout << "Start" << std::endl;
obj.ptr->ConcreteMemberDoSomething();
std::cout << "End" << std::endl;
}
With output:
Ctor start
I expect that I have more debugging to do with my main()
, but I don't understand why the Init
constructor freezes. I'm worried it's something to do with the initialization order, since I've been reading about the static initialization order problem, but I don't know what I could try to fix it since I don't have access to any of the definitions compiled in the dynamic library.