【发布时间】:2012-11-14 13:14:06
【问题描述】:
我对严格的弱排序以及在定义运算符时如何使用它感到困惑
struct Plane
{
std::string name;
int xrudder;
int yrudder;
int wingwidgets;
bool hasLegacyEngine;
};
struct Airport
{
bool securityCheck;
unsigned __int64 capacity;
std::vector<Plane> planes;
};
我想创建一个std::set 的机场。我需要定义 operator
struct cmpless
{
bool operator()(const Airport& left, const Airport& right)
{
//?
}
};
std::set<Airport, cmpless> airportSet;
一个机场“小于”另一个机场是没有意义的。只有当机场的统计数据相等时才有意义。
我如何确定我对 operatoroperator<?
如果可能的话,一个带有解释的例子会很棒!
【问题讨论】:
-
我看到你给每架飞机起了名字,但你的机场没有名字。如果你给机场一个名字,你可以使用词法字符串比较,因为它定义了一个严格的弱排序。
标签: c++ operator-overloading set strict-weak-ordering