typed vtable
Michel Fortin
michel.fortin at michelf.com
Wed Nov 19 07:23:41 PST 2008
On 2008-11-18 10:17:20 -0500, "Jarrett Billingsley"
<jarrett.billingsley at gmail.com> said:
> A pointer template-struct to a virtual member function without knowing
> the target object in advance?
>
> Something like this: http://codepad.org/SXIP2jBL ?
Yeah, I was experimenting with this method while you wrote this. The
sad thing about it is that you need to specify the name of the function
as a string instead of an alias... meaning that a typo will create an
error inside the template's code. Well I've found a trick to avoid that:
template FunctionName(alias f) {
const string FunctionName = (&f).stringof[0..$-2];
}
Using this template, you can get the name of a function from an alias,
but that's mostly a hack.
And also, you can't create such a "pointer" to a private or protected
method and give it to another template that lives outside the class:
the mixin just won't work there because of the protection attribute.
But your template is pretty neat.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list