Compiler Error C2895

'function' : cannot explicitly instantiate a function template that has been declared with dllimport

The compiler cannot explicitly instantiate a function template that has been declared with the dllimport extended attribute. For example:

template<class T> void mf(T) {...
};
template void __declspec(dllimport) mf<int>(int); //error

The following code would work if the function can be inlined, otherwise the function in the DLL will be called and the error will be generated.

template<class T> void mf(T) {...
}
inline template void __declspec(dllimport) mf<int>(int);