Topic: Usage binding of template functions?


Author: stidev@gate.net (Solution Technology)
Date: 1995/04/09
Raw View
I have been able to tell if the standard allows the following.
It seems like I haven't used any new concept.

template<class R, class P> R CASTto( P& p ){ if( ... ) return (R)p; else
...; };

usage:
class MyClass:BaseClass{ ... };
BaseClass e;
MyClass x;
 x = CASTto<MyClass>(e);


Ken Walter





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/04/10
Raw View
stidev@gate.net (Solution Technology) writes:

>I have been able to tell if the standard allows the following.
>It seems like I haven't used any new concept.

>template<class R, class P> R CASTto( P& p ){ if( ... ) return (R)p; else
>...; };

>usage:
>class MyClass:BaseClass{ ... };
>BaseClass e;
>MyClass x;
> x = CASTto<MyClass>(e);

If you are asking whether a function template like "CASTto" is allowed
in the draft standard, yet it is. A function template will no longer
be required to have all template parameters in the function parameter
list, but you will have to provide the missing template parameters
in the invocation -- as you have done.

For the specific case you show, you can get the effect of a cast
to a derived class with a dynamic_cast instead.
--
Steve Clamage, stephen.clamage@eng.sun.com