I have written a simple template class which gives me some problems when I attempt to launch one of its methods.
The (minimum complete) example below shows my problem: I have defined a template class containing a function pointer which is set in the constructor.
#include <windows.h>
template <class T1> class T1Class
{
public:
typedef T1 ( *TCopyNodeData )(const T1& SrcData);
T1Class ( TCopyNodeData CopyNodeData )
{
//.....
}
};
unsigned int CopyIData ( const unsigned int& IData )
{
//.....
return 0;
}
char* CopySData ( const char*& NData )
{
//.....
return nullptr;
}
int APIENTRY wWinMain ( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow )
{
T1Class<unsigned int> MyT1Class1 ( CopyIData ); // ok
T1Class<char*> MyT1Class2 ( CopySData ); // ***** E0289, C2664
return 0;
}
// E0289 no instance of constructor "T1Class<T1>::T1Class [with T1=char *]" matches the argument list
// argument types are : (char *(const char *&NData))
// C2664 'T1Class<char *>::T1Class(T1Class<char *> &&)' : cannot convert argument 1 from 'char *(__cdecl *)(const char *&)' to 'char *(__cdecl *)(const T1 &)'
Now, the first constructor (unsigned int) compiles fine, the second (char*) does not. I do not understand the error message; if I replace T1 with char* in that message I do have two identical parameter types and nothing should be wrong.
Or -- Am I missing something?
constapplies to the top-level ofT, soconst T& == char* const&whenT=char*.