Advertisement

Constructor not called

Started by August 19, 2000 10:42 PM
3 comments, last by RWarden 24 years, 4 months ago
I''m implementing something very similar to pluggable class factories, but running into a large problem. The classes are supposed to be registered by the constructor of a static member of each class, however this contructor isn''t getting called. I''ve tried several things, including taking it outside of the class and putting it into a CPP file, no luck. It won''t even let me set a breakpoint on the var definition. I did get it to work, but I had to put the var definition inside of a function. It''s not too elegant, but it works.. however, I''m still puzzled by why the constructor wasn''t being called outside of a function. The code is: [source] CClassMaker RegIt ( CLSID_MyClass ); [source] Thanks a lot, -RWarden (roberte@maui.net)
> registered by the constructor of a static member of each class

I don''t understand what you are trying to do. What about giving a piece of sample code showing what you tried - more than just a single line.
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Advertisement
Oops, I forgot how the forum can butcher template code. Ok.. CClassMaker is a template class used to register classes. Its constructor adds both a class ID and a creation function for the template type to a global map. As the end result, the class factory allows you to create an object based on it's class ID (an integer). For more information on class factories there's an article on this web site, and a thread much lower on this forum.
So, like I said above, the problem is that the CClassMaker constructor never gets called if the CClassMaker object isn't declared in a function.

-RWarden (roberte@maui.net)

Edited by - RWarden on August 20, 2000 3:56:45 AM
Remember that you have to initialise static members outside of the class definition (in a .cpp file) - if you don''t do this then the class will never be constructed as you aren''t actually creating an instance of it, merely declaring the possibility of an instance.
Thanks, but I did know that . The problem''s something else..

-RWarden (roberte@maui.net)

This topic is closed to new replies.

Advertisement