作者khoguan (Khoguan Phuann)
看板C_and_CPP
标题Re: 请问一个关於iterator的问题...
时间Thu Jul 28 23:48:42 2005
※ 引述《slchen (风城游子(B))》之铭言:
: ※ 引述《slchen (风城游子(B))》之铭言:
: : 有两个程式...其中hamming.cpp里
: : int distance(vector<int> v1, vector<int> v2);
: : 将两个vector传给这个function 然後算两者的hamming distance
: : 然後在counting.cpp中
: : vector < vector < int> > L10;
: : .......
: : for (int m5=0; m5 < L10.size(); m5++)
: : {
: : int d2 = distance ( L10[m5],temp);
: : 把L10[m5] 和temp(两者皆为 vector < int> ) 传给distance这个function
: : 但是compile时有错
: : 好像是说应该用iterator;
: : 请问各位大大 应该怎麽改写呢?...
你自订的函式名称和标准函式库的
template<class Init>
iterator_traits<InIt>::difference_type
distance(InIt first, InIt last);
冲到了!最简单的解法就是自己的函式改取不一样的名字。
这个牵涉到 Argument Dependent Lookup (ADL 又称 Koenig lookup)
像是 max() 或 min() 这种函式名也很容易冲到。
: 我再把error message po出来好了~~
: error 发生在int d2这一行~~
: In instantiation of `std::iterator_traits<std::vector<int, std::allocator<int
: 31 C:\Dev-Cpp\code\counting.cpp instantiated from here
: 129 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_iterator_base_types.h no type
: named `iterator_category' in `class std::vector<int, std::allocator<int> >'
: 在stl_iterator_base_types.h的第129行是写这样的
: typedef typename _Iterator::iterator_category iterator_category;
: 跟iterator有关的..看不太懂error message~~
C++ 和 template 有关的错误讯息真是不好懂呀! XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.130.208.168
1F:推 slchen:谢谢啦~~~... 220.141.56.156 07/29
2F:推 UNARYvvv:哈..话说我先前也看不出来为何会错..原来是同名 61.70.137.117 07/29
3F:→ UNARYvvv:不过若是这种情况,不是应该先以引数型别完全相 61.70.137.117 07/29
4F:→ UNARYvvv:同的 non-template function match 到吗?? 61.70.137.117 07/29
5F:→ UNARYvvv:因为照说他们是在同一个 overloaded set 里面吧 61.70.137.117 07/29
6F:→ UNARYvvv:不知道为何反而编译器会选择 Standard 版的呢?? 61.70.137.117 07/29
7F:推 otpgoodop:namespace不同.... 59.115.76.234 08/06