Quote:Original post by eq
The ImageFormat constructor are never executed.
All code are present in a lib: Image.lib if that's causing problems. The constructor basicly adds the information about the ImageA8 class to a static linked list. Then when I need an image I just call Image::create with the desired format and an Image object of the closest matching format is returned.
Your constructor is probably getting called. Your problem is most-likely attributed to the fact that you are relying on an implementation order of construction. Object construction order is not defined when you are working with multiple translation units (cpp files). You are only guaranteed that objects are constructed in the order they appear in each translation unit, however, the order in which objects from two different translation units are constructed is uncontrollable.
You are saying that the constructor of your object adds itself to a static linked list object, so what's most-likely happening is your constructor for the object is getting called before the constructor for the linked list (so the results of you attempting to add the object to the list are undefined). What's probably happening is the operation doesn't cause error, but the consructor resets the container's state, probably also causing a memory leak (this would be true if the implementation of the linked list has pointer datamembers and the operation to add an item to the list just dynamically allocates a node and assigns its address to the value, since this would work fine with uninitalized data, but when the constructor for the list gets called, it would just set the pointer to 0, causing a memory leak and the appearance of the object having never been added to the list).
A common solution to this is to us a static object inside of a functions, since static objects in functions are initialized on first use. If you need well-defined order of destruction, this solution doesn't work either, so you may be better off working with reference counting if that's the case.