【发布时间】:2014-08-06 13:47:09
【问题描述】:
我有类似的东西
template <typename T>
T func1() { /* ... */ }
template <typename T>
T func2() { /* ... */ }
// many other functions which use the same template line
如果我试试这个
template <typename T>
T func1() { /* ... */ }
T func2() { /* ... */ }
我得到编译错误。
是否有可能只编写一次template 部分并使代码工作?
【问题讨论】:
-
您可以将这些函数包装到结构或类中
-
第二种情况:
unknown type name T代表func2。可能是因为它只识别第一个函数的模板。
标签: c++ class templates namespaces function-templates