by nxkjh » Sat Nov 26, 2011 1:10 pm
You're defining identically named objects with static duration and external linkage in every translation unit that includes this .h file, which is why no two such translation units can be linked together. The include guards "the whole ifdef/define/endif" do something different.
It is also bad style to define a class and an object of that class type in a single statement.
Explain why do you want to "include it there" to see how it can be done in C++. Typical approaches, are: 1) instantiate an object of this type with auto or dynamic duration and access it by reference/smart pointer where needed 2) instantiate an object of this type with static duration in *one* translation unit and use the extern declaration in the other units that must access it, and 3) make it a Singleton and access it via static function such as ImageManager::getInstance()
By the way, I have a feeling that ImageManager::isImageUsed() and ImageManager::getImage() should be declared const, especially seeing how the latter returns a const reference. Do they modify ImageManager while obtaining that bool or that reference?