调用重载*** <unresolved overloaded =“”function =“”type =“”>)'含糊不清

时间:2016-07-28 13:55:18

标签: c++ function overloading

请帮我解决此错误

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(std :: vector :: iterator,std :: vector :: iterator,std :: ostream_iterator,)'是不明确的

1 个答案:

答案 0 :(得分:1)

重写此声明

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

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

否则,您的功能会与标准算法std::copy_if

冲突

由于您使用了derictive

,问题就出现了
using namespace std;

注意代码段中的函数调用没有语法完成。你忘了指定最后一个参数。