我在这里定义了一个数据类型为用户定义对象的集合。
\n#include<bits/stdc++.h>\nusing namespace std;\nclass triplets{\n public:\n int x,y,z;\n triplets(){\n\n }\n triplets(int x,int y,int z){\n this->x=x;\n this->y=y;\n this->z=z;\n }\n\n};\nclass Cmp{\n public:\n Cmp(){};\n bool operator() (const triplets &a, const triplets &b){\n if( a.x == b.x){\n return a.y < b.y;\n }else{\n return a.x < b.x;\n }\n }\n};\nint main(){\n set<triplets,Cmp>s;\n s.insert(triplets(2,4,5));\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n该代码在 c++11 和 c++14 版本中编译良好。但它不能在 c++17 及更高版本中编译。它抛出以下错误。
\n In file included from /usr/include/c++/11/map:60,\n from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,\n from Arrays/TwoPointer/test.cpp:1:\n/usr/include/c++/11/bits/stl_tree.h: In instantiation of \xe2\x80\x98static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, …Run Code Online (Sandbox Code Playgroud)