kam*_*iro 0 c++ comparison class
所以在C++中很多时候你需要创建一个"索引"类.例如:
class GameID{
public:
string name;
int regionid;
int gameid;
bool operator<(const GameID& rhs) const;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我们将GameID表示为pair<string, pair<int, int> >,那么运算符比较就是它.有没有其他方法来获得自动运算符比较而不必使用std :: pair <>?
你得到一个operator<你使用,std::pair因为std::pair实现了一个operator<过载.它std::string作为对中的一种类型使用时也有效,因为它std::string也会重载operator<.
如果您希望能够比较自己类类型的对象,则还需要重载operator<.