次のような場合に適切な関数のオーバーロードを選択する正しい方法は何ですか?正しい関数のオーバーロードを選択するには?
#include <iostream>
#include <algorithm>
/** the correct overload **/
bool predicate(const char& c)
{
return c == '0';
}
/** the wrong overload **/
template< typename CharType >
bool predicate(const CharType& c, int some_other_parameters)
{
return c == '0';
}
std::string
process_string(const std::string& str)
{
std::string result;
std::copy_if(str.begin(),
str.end(),
std::back_inserter(result),
predicate);
return result;
}
int main()
{
std::cout << process_string("AK0NNDK0ASDAS0") << std::endl;
return 0;
}
パラメータ数。 – knivil