[問題] ambiguous call to overloaded function

作者: QQ29 (我愛阿蓉)   2014-09-18 12:21:29
遇到一個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
請教各位
謝謝
作者: azureblaze (AzureBlaze)   2014-09-18 12:30:00
Argument-dependent name lookup因為你的參數iterator是在std下的東西所以他會自動去搜std裡的名稱
作者: carylorrk (carylorrk)   2014-09-18 15:42:00
可以參考 the complete guide 9.2

Links booklink

Contact Us: admin [ a t ] ucptt.com