Original Post
Ok, I figured it would be best to start a new thread, since the old one was a bit confusing... I'm having problem with template class Instantiation. The thing is that I have a class, whith a static variable which is initialized to the value of a static variable in a template class. Something like: template class TemplateClass { public: static SomeData* pData; }; template SomeData* TemplateClass::pData = new SomeData(); class ClassUsingTemplateClassData { public: static SomeData* pData; }; SomeData* ClassUsingTemplateClassData::pData = TemplateClass::pData; After some testing I have come to the conclusion that ClassUsingTemplateClassData::pData is beeing instatiated before the TemplateClass::pData. So when using the TemplateClass::pData we get a crap value ! :( Does anyone know how to solve this? Thank you! Look at this: Just copy this into a .cpp file and run it. You will see in which order the data is instantiated:
The code is simple, and I have commented the important stuff... Would appreciate any help on how to solve this :) Thank you!
|