The following code declares a template, declares an explicit instantiation definition, then declares an explicit instantiation declaration:
template <typename T>
T Double(T number)
{
return number * 2;
}
extern template int Double<int>(int); // declaration
template int Double<int>(int t); // definition
int main(int argc, char* argv[])
{
int n = Double(10);
return 0;
}
gives an error:
error C2929: 'int Double<int>(int)' : explicit instantiation; cannot explicitly force and suppress instantiation of template-class member
in Visual Studio 2012.
I'm under the impression from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1987.htm that this should be valid, since the definition follows the declaration.
Am I missing something?