# Abstract-template-class has linkage errors when defining destructor

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

## 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	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 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 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 =/

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