2016-07-28 56 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根本没有。不用谢。:) –

相关问题