Sign in to follow this  

Abstract-template-class has linkage errors when defining destructor

This topic is 4662 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

Basically, I have an abstract, template-class being used in my resource manager.
template<typename BASETYPE>
class CResource
	{
	//--- MEMBERS ---//
	public:
	typedef  BASETYPE BaseType; 
	int	 nState;		//state of resource
	STRING	 strName;		//name of resource
	BASETYPE Data;		//resource data
	

	//--- METHODS ---//
	public:
	virtual bool	Load(LPCTSTR)		= 0;
	virtual bool	Create(const BASETYPE*)	= 0;
	virtual bool	Release(void)		= 0;
	
	CResource()
		{
		nState	= RES_EMPTY;	
		strName	= "";
		Data	= (BASETYPE)NULL;
		}
	CResource(const CResource&);	
	};



But when I declare or define a destructor for this base class, all classes derived from this get external linakge errors for the method 'Release()'. None of the other methods have this problem (yes, all methods are called somewhere in the code, so that's not an issue). And by not declaring or defining the destructor, everything works just fine. Could this be some issue with an outdated compiler? I AM using MSVC 6.0. Or is this just a feature of templatesd abstract classes?

Share this post


Link to post
Share on other sites
1) Since this is a template class, make sure to put your definitions at the same place as the declaration (that is, don't assume you can put them in another file besides this header file). For instance, your copy constructor needs a definition. The pure virtual functions, of course, do not require a body (except the destructor, if you choose to make it pure virtual).

2) Make sure you declare (and define) a virtual destructor for this class. It does not need to be pure virtual, but it does need to have a body.

3) Try a decent compiler. There should be nothing holding you back from this, as there are several available gratis. :-)

Share this post


Link to post
Share on other sites
Many thanks for the reply NoahAdler, but I figured out what the problem was. I was calling one of the pure methods of the base class in its destructor. Oh well, seemed like a good idea at the time =/

[edit] I guess I could just make it non-pure =)[/edit]

Share this post


Link to post
Share on other sites

This topic is 4662 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