【发布时间】:2011-11-03 23:39:33
【问题描述】:
我在头文件中声明了几个小帮助函数。它看起来像这样:
//contents of foo.h
#ifndef FOO_H
#define FOO_H
void foo1(int a);
template <class mType>
void foo2( mType b);
#endif
//contents of foo.cpp
#include foo.h
void foo1(int a)
{
...
}
template <class mType>
void foo2( mType a)
{
...
}
通常当只有功能模板时,我会添加一个#include "foo.cpp"
在 foo.h 的末尾使模板函数的实现在编译时对编译器可见。然而,当混合函数模板和普通函数时,这种方法似乎不起作用。在这种情况下如何解决模板函数和普通函数?
【问题讨论】: