C++ Derivation Issue

Started by
3 comments, last by ralan 18 years, 9 months ago
I'm a little rusty on my C++ so bare with me. I'm using a game library, that I want to derive a class from. In that library, the sprite class that I want to derive from has it's default constructor set to protected. When I try to derive from it I get the following error:

Zenthar error LNK2019: unresolved external symbol "protected: __thiscall hgeSprite::hgeSprite(void)" (??0hgeSprite@@IAE@XZ) referenced in function "public: __thiscall cEntity::cEntity(void)" (??0cEntity@@QAE@XZ) 

Now I thought even if it was protected I could still derive from it. Any help is appreciated. Thanks! Editted to demangle the forum [Edited by - _the_phantom_ on July 19, 2005 9:56:24 PM]
Advertisement
You declared hgeSprite's constructor, yet you never actually defined it, or at least your definition is not visible from other modules during linking. You probably either never defined it, or you aren't linking with your library from your current project, or you labeled your definition as inline and aren't including its definition in the translation unit where you are calling it.
Well the problem is (I am another person involved with this project) that the hgeSprite class is a pre-built game library. In the class the default constructor , with no arguments, is defined as protected.

So, if I understand you, this class cannot be inherited from because the default constructor was never defined in their hgeSprite.cpp file? And if that is the case, the only way to access this sprite's information in ever "entity" created is to either define hgeSprite as a friend of cEntity, or create an object of hgeSprite IN the cEntity class? I am still getting used to OOP design, so if either of the previous ideas are horrifically bad let me know (and why if possible).

Thanks in advance...

Ralan
Quote:Original post by ralan
So, if I understand you, this class cannot be inherited from because the default constructor was never defined in their hgeSprite.cpp file?

Correct. Either that or you aren't linking to the game library correctly, or you did put the definition of the constructor in a cpp file but you labeled it as "inline" (which in turn will make other modules not be able to access the function).

Quote:Original post by ralan
And if that is the case, the only way to access this sprite's information in ever "entity" created is to either define hgeSprite as a friend of cEntity, or create an object of hgeSprite IN the cEntity class?

No, neither of those will solve the problem (unless you have other constructors that are properly defined). You don't have any logical flaws in the interactions in your code -- the problem is with linking, not compilation. To fix the problem you should recompile the game library and make sure that you have the definition of the constructor not inline and in a cpp file, or in a header included by other files, defining the constructor as inline. If neither of those solve the problem then you aren't linking to your library properly.
Well, I dont have access to the original cpp files, just some prebuilt dll's (this is a directX wrapper) -- so I cant take a look at the cpp's or correct anything and rebuild them. When I do remove the inheritance code though it links fine, even if i declare this sprite class a friend to my cEntity class, or create objects of the sprite class. But, as you were saying, that should only affect the compilation. I did recheck my linker information, and the only two libaries even included in this wrapper are being linked at build time...so I am really not sure what the deal is.

Thanks

Ralan

This topic is closed to new replies.

Advertisement