C++中命名空间内的函数模板的声明问题

C++中,当在命名空间中声明模板函数时,应将函数的声明和实现置于一处,而不是使用“头文件-实现文件”分离的方式,否则可能导致编译错误。

即,建议的方式为:

//HEADER FILE
 
namespace MyNamespace{
 
template<class T>
void MyFuncTemplate(T Param1, T Param2){
    //Function Implementations
}
 
}

参考资料:https://stackoverflow.com/questions/3261093/function-template-in-a-namespace-in-a-separate-file-compiles-fine-but-the-linke

it
除非特别注明,本页内容采用以下授权方式: Creative Commons Attribution-ShareAlike 3.0 License