考虑代码:
...
template <typename T>
void Swap(T &,T &);
template <> void Swap<structEmployee>(structEmployee &,structEmployee &);
int main()
{
template void Swap<char>(char &,char &);
short a=10,b=20;
...
Swap(a,b);
...
...
}
它给了我错误:
expected primary-expression before ‘template’
template void Swap<char>(char &, char &);
答案 0 :(得分:0)
您不能在块范围内实例化模板,它必须在全局范围内:
//Instantiation in global scope
template void Swap<char>(char &,char &);
int main()
//...