public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Default argument for templatized function
@ 2004-05-11 22:44 Adrian Bentley
  2004-05-12  8:32 ` Jonathan Wakely
  2004-05-13  1:03 ` llewelly
  0 siblings, 2 replies; 8+ messages in thread
From: Adrian Bentley @ 2004-05-11 22:44 UTC (permalink / raw)
  To: gcc-help

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-05-13 21:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-11 22:44 Default argument for templatized function Adrian Bentley
2004-05-12  8:32 ` Jonathan Wakely
2004-05-12 17:50   ` Adrian Bentley
2004-05-13  1:10     ` llewelly
2004-05-13  8:05     ` Jonathan Wakely
2004-05-13 21:46       ` Adrian Bentley
2004-05-13 21:48         ` Adrian Bentley
2004-05-13  1:03 ` llewelly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).