W
winterTTr
Hi , I just want to write a template function to accomplish some kind
of action.
But i meet a problem that the compiler always say that "no matching
function for call".
There must be some problem about the function declaration or using,
but i can't find it.
Please help me to point out that the problem is, thanks.
The code is like below( i remove the most of the detail part )
template < typename _Iterator , typename _Compare >
void bubbleSort(
_Iterator __first ,
_Iterator __last ,
_Compare __compare = less< typename
iterator_traits<_Iterator>::value_type >() )
{
typedef typename iterator_traits<_Iterator>::value_type
_value_type;
copy( __first , __last , ostream_iterator< _value_type > ( cout ,
" " ) );
};
int main(int argc, char const* argv[])
{
vector<int> m;
m.push_back( 1 );
m.push_back( 2 );
m.push_back( 3 );
m.push_back( 4 );
bubbleSort( m.begin() , m.end() ); //
error !! Can't find the function to call
bubbleSort( m.begin() , m.end() , less<int>() ); // this is OK.
return 0;
}
Can you tell me why the error comes out when i want to use the default
value?
Or Is there a way to prevent this error as well as using the default
value for the _Compare argument?
of action.
But i meet a problem that the compiler always say that "no matching
function for call".
There must be some problem about the function declaration or using,
but i can't find it.
Please help me to point out that the problem is, thanks.
The code is like below( i remove the most of the detail part )
template < typename _Iterator , typename _Compare >
void bubbleSort(
_Iterator __first ,
_Iterator __last ,
_Compare __compare = less< typename
iterator_traits<_Iterator>::value_type >() )
{
typedef typename iterator_traits<_Iterator>::value_type
_value_type;
copy( __first , __last , ostream_iterator< _value_type > ( cout ,
" " ) );
};
int main(int argc, char const* argv[])
{
vector<int> m;
m.push_back( 1 );
m.push_back( 2 );
m.push_back( 3 );
m.push_back( 4 );
bubbleSort( m.begin() , m.end() ); //
error !! Can't find the function to call
bubbleSort( m.begin() , m.end() , less<int>() ); // this is OK.
return 0;
}
Can you tell me why the error comes out when i want to use the default
value?
Or Is there a way to prevent this error as well as using the default
value for the _Compare argument?