[問題] std::list sort()

看板C_and_CPP (C/C++)作者 (硬體)時間10年前 (2015/05/26 20:50), 編輯推噓3(302)
留言5則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) G++ 4.1.3 問題(Question): sort() 這個function是針對class的第一個成員做排序 有辦法針對第二個成員嗎? 程式碼(Code):(請善用置底文網頁, 記得排版) class AAA { friend ostream &operator<<(ostream &, const AAA &); public: char x; int y; float z; AAA(); AAA(const AAA &); ~AAA(){}; AAA &operator=(const AAA &rhs); int operator==(const AAA &rhs) const; int operator<(const AAA &rhs) const; }; 比如說 如果用 sort() 的話 會針對 char x 這個第一個成員作排序 有辦法針對 int y做排序嗎? 謝謝 另外想問說 std::list 有哪些函數可以使用哪裡查的到呢? 比如 .push_front() .push_back() .merge() 等等 我在網路上查到的都是部份而已 謝謝 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.89.67 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1432644603.A.8C0.html

05/26 20:54, , 1F
C++不是有官方函數列表和說明嗎
05/26 20:54, 1F

05/26 20:54, , 2F
你的operator<實作?
05/26 20:54, 2F


05/26 21:35, , 4F
自定義小於
05/26 21:35, 4F

05/26 22:23, , 5F
有C++11的話餵一個lambda進去就好了
05/26 22:23, 5F
文章代碼(AID): #1LP6lxZ0 (C_and_CPP)
文章代碼(AID): #1LP6lxZ0 (C_and_CPP)