FlyingCode

导航

 

今天写代码的时候遇到一个问题, 在.h文件中申明了一个模板函数并且在.cpp文件中定义.

之后用其他的cpp文件include了这个cpp文件, 结果发现无法正常调用这个模板函数.

之后参考了stackoverflow给出的答案, 发现不能把模板函数的定义与声明分离在两个文件中, 因为模板函数不能被预编译

 

However, due to the nature of templates it is common practice to put all the code for the class in the header. Template code cannot be pre-compiled (that is, it cannot be compiled into a shared library or DLL) because the type information changes when the code is used.

https://stackoverflow.com/questions/11052027/c-templates-error-no-matching-function-for-call-stdvectorint-stdallocat

posted on 2018-04-10 14:46  hhbeast  阅读(368)  评论(0)    收藏  举报