exporting template member function of template class from dll



Hi all!

I have something like that :

******** dll.h ********

#ifdef CC_EXPORTS // CC_EXPORTS is defined in the dll.
#define __CC_API __declspec(dllexport)
#define __CC_TEMPLATE_API( iTemplate ) template class __CC_API
iTemplate;
#else
#define __CC_API __declspec(dllimport)
#define __CC_TEMPLATE_API( iTemplate ) extern template class __CC_API
iTemplate;
#endif

namespace CC
{
template<class TChar = char>
class SString
{
...

int Length() const
{
...
};

template<class _TChar>
void Append( const _TChar* ipFormat, ... )
{
...
};
};
}

__CC_TEMPLATE_API( CC::SString<char> )

******** exe.cpp ********

#include "dll.h" // CC_EXPORTS is defined in the dll.

using namespace CC;

int main()
{
SString<char> str;
int len = str.Length();
str << "My SString : ";
str.Append( "%s %.3f\n", "double", 1.2156 );
str.Append( "%s 0x%04X\n", "Hexadecimal :", 2005 );

return 0;
}

*************************

I have no problem with non-template member functions, but with template
member functions (like Append), the VC++ 6 Compiler gives me an error :

dll.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: void __cdecl
CC::SString<char>::Append(char const *,...)"
(__imp_?Append@?$SString@D@CC@@QAAXPBDZZ)

How can I resolve this problem ? I would like to have the code of the
Append<_TChar> member function in the dll (for _TChar = char and _TChar
= wchar_t).

Thanks,

.



Relevant Pages

  • Re: New to C++ entirely (HELP!)
    ... MFC and ATL are C++ class libraries that target native Win32 development. ... int __stdcall WinMain ... using namespace System::IO; ... static void Main2; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Personal project, extending Scheme to OOP
    ... I've been passing around a reference to a single namespace ... unsigned int type: 4; ...
    (comp.lang.scheme)
  • [PATCH 2/8] ns: Introduce the setns syscall
    ... of containers but in the context of people doing interesting ... There is also demand in the context of containers to have ... int setns; ... an the name of the namespace you think you are changing, ...
    (Linux-Kernel)
  • Re: Late binding with unmanaged code
    ... I wonder can someone else show an example of importing GetProcAddress ... Scott Blood ... I don't know if i am missing a namespace. ... public extern static int InvokeFunc(int funcptr, int hwnd, string ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with a sll on PPC 2002
    ... each piece of data, and both TCHAR *s? ... int flagVal = GetInfosBatt(); ... > nFlagBatt = powerStatusEx.BatteryFlag; ...
    (microsoft.public.pocketpc.developer)