I have been having link problems (see my previous post) and I got
around to trying one by one, different combinations since I absolutely
could not figure out why things weren't working. I have done exactly
the same type of thing before and it worked like a charm!
I got around to wondering finally if it could be a problem with the way
I have organized things.
Let's assume a template class declaration as follows:
template<typename DeallocType>
class DefaultDeallocator : public virtual Deallocator<DeallocType>
{
public:
DefaultDeallocator();
virtual ~DefaultDeallocator();
virtual void Delete(DeallocType*);
virtual void DeleteObjectArray(DeallocType*);
virtual void DeletePointerArray(DeallocType**, unsigned long);
};
This is in a header called DefaultDeallocator.h (duh! :)
I have the definition in a module called DefaultDeallocator.cpp.
template<typename DeallocType>
DefaultDeallocator<DeallocType>::DefaultDeallocator()
{
}
template<typename DeallocType>
DefaultDeallocator<DeallocType>::~DefaultDeallocator()
{
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>::Delete(DeallocType* obj)
{
if(NULL != obj)
{
delete obj;
}
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>
::DeleteObjectArray(DeallocType* array)
{
if(NULL != array)
{
delete[] array;
}
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>
::DeletePointerArray(DeallocType** ptrarray, unsigned
long num)
{
if(NULL != ptrarray &&
num > 0)
{
for(unsigned long i = 0; i < num; ++i)
{
delete ptrarray[i];
}
}
}
Could it be that because the definition is in a module as opposed to
being completely in the header itself, that I am getting unresolved
external link problems. Here are my errors:
Creating library Debug/SmartPointer2.lib and object
Debug/SmartPointer2.exp
Test.obj : error LNK2019: unresolved external symbol "public: virtual
__thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::~DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>(void)"
(??1?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAE@XZ)
referenced in function "void __cdecl
Test_Deallocator_Construction(void)"
(?Test_Deallocator_Construction@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public:
__thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>(void)"
(??0?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@QAE@XZ)
referenced in function "void __cdecl
Test_Deallocator_Construction(void)"
(?Test_Deallocator_Construction@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::Delete(class
MCMDocumentCache::ReferenceCounter *)"
(?Delete@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAVReferenceCounter@2@@Z)
referenced in function "void __cdecl Test_Deallocator_Delete(void)"
(?Test_Deallocator_Delete@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DeleteObjectArray(class
MCMDocumentCache::ReferenceCounter *)"
(?DeleteObjectArray@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAVReferenceCounter@2@@Z)
referenced in function "void __cdecl
Test_Deallocator_DeleteObjectArray(void)"
(?Test_Deallocator_DeleteObjectArray@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DeletePointerArray(class
MCMDocumentCache::ReferenceCounter * *,unsigned long)"
(?DeletePointerArray@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAPAVReferenceCounter@2@K@Z)
referenced in function "void __cdecl
Test_Deallocator_DeletePointerArray(void)"
(?Test_Deallocator_DeletePointerArray@@YAXXZ)
Debug/SmartPointer2.exe : fatal error LNK1120: 5 unresolved externals
If my supposition is correct, that kind of seems funny. Supposing I
were distributing a library and I didn't want to expose my
implementation, what would I do?
thanks,
-vijai.