fre*_*low 6 c++ templates function return-value template-specialization
假设我有一个函数模板,其中type参数仅用作返回类型:
template <typename T>
T foo()
{
return whatever;
}
Run Code Online (Sandbox Code Playgroud)
那么专门化该函数模板的正确语法是什么?以下两个似乎都有效:
template <>
std::string foo()
{
return whatever;
}
template <>
std::string foo<std::string>()
{
return whatever;
}
Run Code Online (Sandbox Code Playgroud)
这两者有什么区别吗?如果没有,那么惯用的方式是什么?
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |