这个报错是什么意思

li4c 2014-11-05 10:59:53
这种报错是什么意思?
/*************************************************************************
> File Name: t.cpp
> Author: Jukay
> Mail: hellojukay@gmail.com
> Created Time: 2014年11月05日 星期三 22时22分26秒
************************************************************************/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int>& function(vector<int> &v1, vector<int> &v2)
{
vector<int> tmp = v1;
for(auto a : v2)
tmp.push_back(a);
auto iter = unique(tmp.begin(), tmp.end());
for(; iter != tmp.end(); ++iter)
v1.erase(iter);
return v1;
}

int main()
{
int tmp;
int m,n;
vector<int> a;
vector<int> v1,v2;
vector<vector<int>> result;
while(1)
{
cin >> n >> m;
if( n == 0 && m == 0)
break;
for(int i = 0; i< n; ++i)
{
cin >> tmp;
v1.push_back(tmp);
}
for(int i = 0; i< m; ++i)
{
cin >> tmp;
v2.push_back(tmp);
}
a = function(v1,v2);
result.push_back(a);
v1.clear();
v2.clear();
}
for(auto a : result)
{
if(!a.size())
cout <<" NULL" << endl;
else
{
sort(a.begin(), a.end());
for(auto i : a)
cout << i << ' ';
cout << endl;
}
}

return 0;
}

错误如下
jukay@desktop:~/csdn$ sudo g++ -std=c++11 t.cpp
t.cpp: In function ‘int main()’:
t.cpp:46:6: error: reference to ‘function’ is ambiguous
a = function(v1,v2);
^
t.cpp:13:14: note: candidates are: std::vector<int>& function(std::vector<int>&, std::vector<int>&)
vector<int>& function(vector<int> &v1, vector<int> &v2)
^
In file included from /usr/include/c++/4.8/bits/stl_algo.h:66:0,
from /usr/include/c++/4.8/algorithm:62,
from t.cpp:10:
/usr/include/c++/4.8/functional:1866:11: note: template<class _Signature> class std::function
class function;
^
...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
勤奋的小游侠 2014-11-06
  • 打赏
  • 举报
回复
error: reference to ‘function’ is ambiguous a = function(v1,v2); 把这句翻译一下就知道了。function语义不清,有重名的。
brookmill 2014-11-05
  • 打赏
  • 举报
回复
引用 楼主 u013163178 的回复:
/usr/include/c++/4.8/functional:1866:11: note: template<class _Signature> class std::function
和std::function的名字冲突了。 把你的function函数随便改个名字就好了。

64,671

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧