[問題] ambiguous call to overloaded function

看板C_and_CPP (C/C++)作者 (我愛阿蓉)時間11年前 (2014/09/18 12:21), 11年前編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
遇到一個compile error 但我看不出來錯的原因是什麼 我寫一個partition function例如 template<typename Iterator, class Predicate> Iterator partition(Iterator begin, Iterator end, Predicate pred) { return begin; } 然後 #include <algorithm> int main() { std::vector<int> vec; partition(vec.begin(), vec.end(), [](int i){return true; }); } compile error 就說 partition 這function ambiguous了 不解的是 algorithm裡面的partition包在namespace std底下 跟我這有啥關係 我也確定我沒自己寫using namespace std; 而若我改成::partition(....); 就沒問題了 或是拔掉algorithm 也可以compile 過, 但我會用到algorithm的其他method 所以不能拔 我是用VC 而我請朋友在GCC驗證 也說會error 請教各位 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.58.205 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1411014092.A.65A.html ※ 編輯: QQ29 (118.163.58.205), 09/18/2014 12:23:26

09/18 12:30, , 1F
Argument-dependent name lookup
09/18 12:30, 1F

09/18 12:30, , 2F
因為你的參數iterator是在std下的東西
09/18 12:30, 2F

09/18 12:30, , 3F
所以他會自動去搜std裡的名稱
09/18 12:30, 3F

09/18 15:42, , 4F
可以參考 the complete guide 9.2
09/18 15:42, 4F
文章代碼(AID): #1K6btCPQ (C_and_CPP)
文章代碼(AID): #1K6btCPQ (C_and_CPP)