[問題] 關於std:sort問題

看板C_and_CPP (C/C++)作者 (Light)時間13年前 (2012/10/16 20:42), 編輯推噓-1(012)
留言3則, 2人參與, 最新討論串1/1
#include <algorithm> #include <iostream> #include <cstdio> #include <vector> bool cmp(int x , int y ) { return x < y; } int main() { std::vector<int> test; test.push_back( 1 ); test.push_back( 3 ); test.push_back( 2 ); sort( test.begin(), test.end(), cmp ); std::min( 1,2 ); return 0; } 這一段 可以用 g++ test.cpp gcc 4.4.0 gcc 4.5.2 這兩個都可以過 但奇怪的是sort沒加std:: 不知道為什麼還能過 但min就一定要加std:: 請問sort不是在std namespace中是刻意設計的嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.132.131 ※ 編輯: wind00962 來自: 36.226.56.133 (10/17 20:46)

10/17 21:22, , 1F
Google: ADL
10/17 21:22, 1F

10/17 21:22, , 2F
Argument-dependent name lookup
10/17 21:22, 2F

02/18 14:44, , 3F
跟人文章一模一樣...
02/18 14:44, 3F
文章代碼(AID): #1GVLOvWs (C_and_CPP)
文章代碼(AID): #1GVLOvWs (C_and_CPP)