Static libary linker problem

Started by
3 comments, last by chollida1 19 years, 3 months ago
Ladies and Gents, hoping for advice ! I have an MFC project that is creating an object CMs3dModel which is inherited from CModel in the base class (CModel) I have defined a function as such virtual void UnLoad(void) = 0; and in the base class destructor I call this function to clean up the object. But when I try to compile the main MFC project, i get the following error Models.lib(Model.obj) : error LNK2019: unresolved external symbol "public: virtual void __thiscall CModel::UnLoad(void)" (?UnLoad@CModel@@UAEXXZ) referenced in function "public: virtual __thiscall CModel::~CModel(void)" (??1CModel@@UAE@XZ) This is driving me insane as I have provided the overloaded instance in the CMs3dModel class. Any idea why this is not working?? The static Lib compiles with no problems! Thanks peeps Paul.
Advertisement
I have a couple ideas about why it could be so, but nothing really tangible.
As a workaround, try something like this:

#include <stdexcept>virtual void UnLoad(void) = 0 {   throw std::logic_error("Pure virtual function CModel::UnLoad() "                         "should never be called");}


Before you ask - yes, you can provide a function body for a pure virtual function.

Here, if it does get called, that means there's a problem... try it out.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It happens because your derived class calls teh base classes destructor. The base class then has to call its pure virutal method. Which is illegal since there isn't one.

Remove the pure virtual call from the destructor since it shouldn't be there. Calling virutal methods from a cstr or dstr is a very common mistake to make:)

Don't do it:)

Cheers
Chris
CheersChris
Guys, Thanks for the help, I see your point about the calling the pure virtual from the base destructor. I guess that you mean if this was allowed, the base destructor would get called last and try to call a function in a destroyed object!

another question (same topic)

is this allowed

class cBase{public:void someFunc(int i);protected:void someFunc(void) = 0;}class coverload : public CBase{private:void someFunc(void);}void CBase::someFunc(int i){//Do something with i;someFunc();};


I know that the implemeentauons are missing and that there is no virtual ect, ut I just wanted a simple explanation!

basically, can I overload an existing (implemented) function in my inherited class but with diff parameters???

Paul
You can overload a method with different parameters :)

CHeers
Chris
CheersChris

This topic is closed to new replies.

Advertisement