c++ less operator overload, which way to use?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For example: in a C++ header file, if I defined a struct Record and I would like to use it for possible sorting so that I want to overload the less operator . Here are three ways I noticed in various code. I roughly noticed that: if I'm going to put Record into a std::set , map , priority_queue , … containers, the version 2 works (probably version 3 as well); if I'm going to save Record into a vector<Record> v and then call make_heap(v.begin(), v.end()) etc.. then only version 1 works. struct Record { char c; int num; //version 1 bool