64,637
社区成员
发帖
与我相关
我的任务
分享
include <stdlib.h>
#include <stdio.h>
#include <map>
#include <string>
using namespace std;
struct A{
int a;
int b;
bool operator < ( const A rhs) const {return a < rhs.a;}
};
int main()
{
map<A, string> m;
A a = {1, 2};
m.insert(pair<A, string>(a, "ok"));
system( "pause" );
return 0;
}
定义为友元
struct A
{
friend bool operator < (cosnt A& ,const A&);
};
bool operator < (cosnt A& x,const A& y)
{
}
写一个
bool operator < (const A& x, const A& y)
{
}
然后
map<A, 其它值>
就行了.