Default argument for templatized function
Adrian Bentley
adruab@voria.com
Tue May 11 22:44:00 GMT 2004
Ok so here's my problem, I have this templatized class (with T). And
for it I'm defining a templatized member function (with F), I want the
function to take a comparison operation as a member to make it more
flexible.
I'm defining:
template < typename T >
class myclass
{
public:
template < typename F >
bool valid(const F & func = std::less<T>()) const
{
//... use func as a binary function ...
}
};
then in my cpp file else where (the instance is using T = float), I'm
calling:
myclass_inst.valid()
and I get this error:
2465: no matching function for call to
`mynamespace::myclass<float>::valid()'
this is the only error I get (hence I am not including the rest of the
build messages), and I have not been able to resolve this.
It is bizarre because I'm defining a non-member function below like so:
template < typename T, typename F >
void operation(const myclass<T> &r1, const myclass<T> &r2, const F &
func = std::less<T>())
{
//... compare stuff ...
}
and it works just fine!!!!!!
Not only that, but if I manually pass that comparison functor in the
call it works just fine:
myclass_inst.valid(std::less<float>())
MY @!*$(@#*&$*. I've tried putting typename everywhere around the
parameter value, typedefing for T, etc. nothing works. It's crazy....
I would be greatful for any clues.
Adruab
More information about the Gcc-help
mailing list