Re: Templates question
Re: Templates question
- Subject: Re: Templates question
- From: David Fang <email@hidden>
- Date: Sun, 25 Feb 2007 05:09:03 -0500 (EST)
> >> template <typename T, typename C, T (C::*getter)() const> class
> >> CrazyTemplate
> >> {
> >>
> >> };
> >
> Sorry, my example was incomplete, but implied above:
>
> class Tapir
> {
> int getSomething() const;
>
> CrazyTemplate<int, Tapir, getSomething> flyingAlpaca;
> };
>
> As far as I can tell, this is disallowed by the C++ standard. VC++
> swallows it whole.
>
> GCC has this to say:
>
> template.cpp:11: error: 'int Tapir::getSomething() const' cannot
> appear in a constant-expression
> template.cpp:11: error: template argument 3 is invalid
Hi Ladd,
Try this:
class Tapir
{
int getSomething() const;
CrazyTemplate<int, Tapir, &Tapir::getSomething> flyingAlpaca;
};
Semantically, pointer-to-members have always been allowed in templates.
Syntactically, I'm not certain if member functions are required to be
qualified, that is, I'm not sure if your original version is standard, or
if gcc is just failing to pick it up. Better find a language lawyer.
(IANALL) :)
David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
http://www.csl.cornell.edu/~fang/
-- (2400 baud? Netscape 3.0?? lynx??? No problem!)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden