Re: A template that calls a different function based on the object passed into the template
Ivan Novick wrote:
I need to write a template function that will call a function whose
name will depend on a parameter to the template, but I can't see how
to do it.
So for example:
void ZoomMyType()
{
}
struct MyType
{
};
void ZoomOtherType()
{
}
struct OtherType
{
};
template<? T> // what should ? be
void do_it()
{
ZoomT();
}
int main(int argc, char**argv)
{
do_it<MyType>();
do_it<OtherType>();
return 0;
}
===========
It can not be a macro, because this do_it will subsequently be used in
a further template.
===========
Take a look at the FAQ (if you haven't yet), section 35. In case it
isn't obvious from there, you can define two specialisations of your
'do_it' template, one on MyType, the other on OtherType and inside
call your ZoomXX function, respectively.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]