本文发表在 rolia.net 枫下论坛#include <string>
using std::string;
#include <map>
using std::map;
class A {
public:
A(const string &s) : _s(s) { }
bool operator<(const A& a) const { return _s < a._s; }
string _s;
};
int main()
{
map<A, int> m;
char* s = "abc";
A foo(string(s));
map<A, int>::iterator iter = m.find(foo);
}
---
I'm using gcc version 3.2.2 and this is the error message:
---
wtf.cpp: In function `int main()':
wtf.cpp:20: no matching function for call to `std::map<A, int, std::less,
std::allocator<std::pair<const A, int> > >::find(A
(&)(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >))
'
/usr/include/c++/3.2.2/bits/stl_map.h:332: candidates are:
std::_Rb_tree<_Key,
std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key,
_Tp> >,
_Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare,
_Alloc>::find(const _Key&) [with _Key = A, _Tp = int, _Compare =
std::less, _Alloc = std::allocator<std::pair<const A, int> >]
/usr/include/c++/3.2.2/bits/stl_map.h:345:
std::_Rb_tree<_Key,
std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key,
_Tp> >,
_Compare, _Alloc>::const_iterator std::map<_Key, _Tp, _Compare,
_Alloc>::find(const _Key&) const [with _Key = A, _Tp = int, _Compare =
std::less, _Alloc = std::allocator<std::pair<const A, int> >]更多精彩文章及讨论,请光临枫下论坛 rolia.net
using std::string;
#include <map>
using std::map;
class A {
public:
A(const string &s) : _s(s) { }
bool operator<(const A& a) const { return _s < a._s; }
string _s;
};
int main()
{
map<A, int> m;
char* s = "abc";
A foo(string(s));
map<A, int>::iterator iter = m.find(foo);
}
---
I'm using gcc version 3.2.2 and this is the error message:
---
wtf.cpp: In function `int main()':
wtf.cpp:20: no matching function for call to `std::map<A, int, std::less,
std::allocator<std::pair<const A, int> > >::find(A
(&)(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >))
'
/usr/include/c++/3.2.2/bits/stl_map.h:332: candidates are:
std::_Rb_tree<_Key,
std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key,
_Tp> >,
_Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare,
_Alloc>::find(const _Key&) [with _Key = A, _Tp = int, _Compare =
std::less, _Alloc = std::allocator<std::pair<const A, int> >]
/usr/include/c++/3.2.2/bits/stl_map.h:345:
std::_Rb_tree<_Key,
std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key,
_Tp> >,
_Compare, _Alloc>::const_iterator std::map<_Key, _Tp, _Compare,
_Alloc>::find(const _Key&) const [with _Key = A, _Tp = int, _Compare =
std::less, _Alloc = std::allocator<std::pair<const A, int> >]更多精彩文章及讨论,请光临枫下论坛 rolia.net