Original Post
Hello, I have a list of classes which all in some way needs to be initialized before any code is executed, to accomplish this I have created a simple maintain class:
template <typename Type>
class maintain_class {
public:
maintain_class() {
Type::init_class();
}
~maintain_class() {
Type::release_class();
}
};
Now, in each cpp defining the implementation of a certain class i create a static instance of this maintain_class. This should work and to my understanding of the c++ standard this variable should be instantiated before any other code. This does work in most cases, but in some I don't explicitly use the class in question and in those seldom cases the maintain_object will not be instantiatet. BUT if I create an instance of the class "being maintained" (note: i dont need to create the maintain_class object myself) it all works perfectly. Is this a compiler bug or not? I have checked the compiler settings and I could not find anything solving my problem. The compiler in use is MSVS71. Regards References: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_pluslang_initialization_of_static_objects.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_pluslang_additional_startup_considerations.asp