函数模板过载问题
function template overload issue
为什么我收到一个错误说:
- 错误 C2668:"max":对重载函数的不明确调用
- 错误 C2780:"常量 T 和最大值(常量 T &,常量 T 和,常量 T &)":需要 3 个参数 - 提供 2 个参数。
在以下代码中:
template<typename T>
inline T const& max(T const& i, T const& j)
{
cout<<"Using template with 2 args."<<endl;
return (i>j) ? i : j;
}
template<typename T>
inline T const& max(T const& i, T const& j, T const& k)
{
cout<<"Using template with 3 args."<<endl;
return max(max(i,j),k);
}
void main()
{
cout<< ::max(1,2,3)<<endl;
}
在调用它之前,我已经定义了 2 参数模板函数。
删除using namespace std
,因为有std::max
参与搜索,这就是您收到第一个错误的原因。第二个错误只是说,有明确的变体,但它们应该收到 3 个参数。
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 将重载的成员函数传递给函数模板
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 以下代码中的函数模板有什么问题?
- 基于 SFINAE 的特征实现问题与函数模板重载
- 使用具有默认参数的函数模板进行 decltype 会使结果混乱(一个有趣的问题或 gcc 的错误)
- 函数模板参数包问题
- 实例化函数模板的编译问题
- 将多个初始值设定项列表传递到可变参数函数模板时遇到问题
- 函数模板查找问题
- 函数模板过载问题
- 为对象指针映射编写函数模板时出现问题
- 类和函数模板实例化的Visual Studio dll导出问题
- 函数模板的问题
- 关于实现静态成员函数模板时重定义错误的c++问题
- 将引用显式传递到不需要引用的函数模板中会导致问题吗?
- 解决函数模板部分专用化问题
- 找到项目函数模板给我的问题
- c++函数模板,Int形参问题