template Container sub_con(Container &con, const ElemType &val),为什么会出现连接错误啊?

complayer 2002-05-07 10:30:48
#include <vector>
#include <list>
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>
using namespace std;

template <typename Container, typename ElemType>
Container sub_con( const Container &con, ElemType &val);

void main(int argc, char * argv)
{
const int elem_size=8;

int ia[elem_size]= { 12, 8, 43, 0, 6, 21, 3, 7};
vector<int> ivec(ia, ia+elem_size);

vector<int> ivec2=sub_con(ivec, elem_size);

return;
}

template <typename Container, typename ElemType>
Container sub_con(Container &con, const ElemType &val)
{
Container local_con(con);
sort( local_con.begin(), local_con.end());

Container::iterator iter=
find_if( local_con.begin(), local_con.end(), bind2nd(greater<ElemType>(), val));

local_con.erase(iter, local_con.end());
return local_con;
}
...全文
180 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
complayer 2002-05-08
  • 打赏
  • 举报
回复
哇,怎么会这样啊!
微软的笨蛋乱报错,编译都通过了,明明是链接错误可是还是编译错误!
谢谢,主要我不知道哪些用法是可以的,所以不太会找错!
他为什么不报函数原型找不到的错误,那我可能会去检查一下函数的声明和实现是否一致!
寂寞漂泊 2002-05-07
  • 打赏
  • 举报
回复
不亏是版主呀,佩服佩服呀
babysloth 2002-05-07
  • 打赏
  • 举报
回复
第2个参数又多了const!
babysloth 2002-05-07
  • 打赏
  • 举报
回复
呵呵,那当然。
声明是template <typename Container, typename ElemType>
Container sub_con( const Container &con, ElemType &val);

实现里第一个参数少了const!
寂寞漂泊 2002-05-07
  • 打赏
  • 举报
回复
用的头文件好多呀

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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