C++使用template时报“有多个重载函数 与参数列表匹配”错误
来源:互联网 发布:2017中日贸易数据 编辑:程序博客网 时间:2024/04/29 16:52
今天在做《Essential C++》里面的练习题的时遇到的这个问题。
先看代码,是一段很简单的代码:
#include <iostream>#include <vector>#include <algorithm>using namespace std;template <typename T>inline T max(T x, T y){return x > y ?x:y;}template <typename T>inline T max(vector<T> &x){return *max_element(x.begin(), x.end());}int main(){cout<<max(1,2)<<endl;return 0;}
vs上报告“有多个重载函数 max 与参数列表匹配”。这个错误觉得有点无辜……
然后定位了一下max函数,看了看重载的函数
原来如此……忘了系统也提供max函数了……所以平时做练习函数名称之类的也要注意啊……
解决办法:
(1)改自定义的函数名称
(2)不使用using namespace std;
(3)将调用改为:
cout<<::max(1,2)<<endl;//表示调用,本文件中的max函数
- C++使用template时报“有多个重载函数 与参数列表匹配”错误
- 错误:没有与参数列表匹配的 重载函数
- MFC 错误:没有与参数列表匹配的 重载函数
- 错误:没有与参数列表匹配的 重载函数
- MFC 错误:没有与参数列表匹配的 重载函数
- VS2010 有多个重载函数"sqrt"实例与参数列表匹配
- 没有与参数列表匹配的 重载函数 AfxMessageBox
- 没有与参数列表匹配的 重载函数 AfxMessageBox
- 没有与参数列表匹配的 重载函数 AfxMessageBox
- 没有与参数列表匹配的 重载函数 AfxMessageBox
- 【VC++】没有与参数列表匹配的 重载函数 AfxMessageBox
- 没有与参数列表匹配的 重载函数 AfxMessageBox()
- 没有与参数列表匹配的重载函数 AfxMessageBox()
- VS2013 C++有多个重载函数“sqrt”实例与参数列表匹配
- str.Format() Error: 没有与参数列表匹配的重载函数
- 使用CreateThread 时报错,函数调用缺少参数列表
- 函数重载与匹配
- 《Essential C++》泛型之 模板函数 Template Functions 与 重载函数 Overloaded Functions
- hdu2001
- hdu2002
- 通过progress_timer组件扩展计时精度
- mysql 的max_connections和max_user_connections 的区别
- hdu2003
- C++使用template时报“有多个重载函数 与参数列表匹配”错误
- Fedora安装Nidia显卡驱动
- STEINER POINT
- Fedora 16安装MPlayer 播放器
- 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
- java list
- 论 NoSQL 的数据模型
- C 代码----在MCU中构建消息队列
- 删除字符串中多余的空格