2016-07-28 53 views
0

請幫助我如何解決這個錯誤通話超載*** <懸而未決的重載函數類型>)「不明確

template <typename Inputlterator, typename Outputlterator, typename Predicate> 
Outputlterator copy_if(Inputlterator begin, Inputlterator end, Outputlterator destBegin, Predicate p) 
{ 
    return remove_copy_if(begin, end,destBegin, not1(ptr_fun(p))); 
} 
template <class T> bool is_not_3(T val) { 
    return val != 3; 
} 
void foo() { 
    vector<int> v; 
    v.push_back(1); 
    v.push_back(2); 
    v.push_back(3); 
    copy_if(v.begin(), v.end(), ostream_iterator<int>(cout, " "), is_not_3<int>); 
} 

我得到一個錯誤說 是:錯誤:調用的重載」 copy_if (標準::向量:迭代,性病::向量:迭代,性病:: ostream_iterator,)」不明確

回答

0

重寫此語句

copy_if(v.begin(), v.end(), ostream_iterator<int>(cout, " "), //...); 

::copy_if(v.begin(), v.end(), ostream_iterator<int>(cout, " "), //...); 
^^^ 

否則與標準算法std::copy_if

問題arised由於使用由你,在你的代碼片段中的函數調用derictive

using namespace std; 

,請注意你的函數的衝突是不是syntaxically完了。你忘了指定最後一個參數。

+0

感謝您的回覆Vlad。對不起,最後一個參數有很多空格,所以不可見。我編輯了這篇文章。添加範圍解析有助於解決錯誤。非常感謝 –

+0

@ user2166368根本沒有。不用謝。:) –

相關問題