下記ソースで期待通りにソートされません。
なぜでしょうか?
c++
1#include "stdafx.h" 2#include<list> 3#include<iostream> 4 5class pos{ 6public: 7 int x; 8 int y; 9 bool operator<( const pos &rhs ) const 10 { 11 return x < rhs.x; 12 } 13}; 14 15int main() 16{ 17 std::list<pos> lst = { {2,3},{4,5},{1,2} }; 18 for( auto itr = lst.begin(); itr != lst.end(); ++itr ) { 19 std::cout << itr->x << "\n"; 20 } 21 std::cout << lst.size(); 22 lst.sort(); 23 getchar(); 24 return 0; 25} 26 27
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/29 23:14