Sign in to follow this  

Static libary linker problem

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this