- 论坛徽章:
- 0
|
以下是程序:
- #include <stdio.h>;
- #include <string.h>;
- #include <map>;
- using namespace std;
- struct aaa
- {
- int b;
-
- bool operator <(const aaa &a)
- {
- if(b<a.b)
- return true;
- return false;
- };
- };
- typedef map<aaa,int>; tmap;
- int main()
- {
- tmap m_tmap;
- aaa a;
- aaa b;
- a.b=1;
- m_tmap.find(a);
- return 0;
- }
复制代码
编译错误:
[king@e2p testcode]$ g++ -o test test.cpp
/usr/include/g++-3/stl_function.h: In method `bool
less<_Tp>;: perator() (const _Tp &, const _Tp & const [with _Tp =
aaa]':
/usr/include/g++-3/stl_tree.h:1121: instantiated from `_Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc>;::find (const _Key & [with _Key = aaa, _Value = pair<const aaa, int>;, _KeyOfValue = _Select1st<pair<const aaa, int>; >;, _Compare = less<aaa>;, _Alloc = allocator<int>;]'
/usr/include/g++-3/stl_map.h:187: instantiated from `map<_Key, _Tp, _Compare, _Alloc>;::find (const _Key & [with _Key = aaa, _Tp = int, _Compare = less<aaa>;, _Alloc = allocator<int>;]'
test.cpp:24: instantiated from here
/usr/include/g++-3/stl_function.h:111: passing `const aaa' as `this'
argument of `bool aaa: perator< (const aaa & ' discards qualifiers
大家看看是哪里有问题啊!! |
|