"Steve Schlesinger" <sschlesinger@cox.net> wrote in message
news:nxW5g.3022$_m5.232@fed1read09...
: Suppose you have
....
: template<class T> void SomeFcn( T t ) {…};
....
: These are both legal:
:
: SomeFcn( a );
: SomeFcn<B>( b );
:
: The question is: When (if ever) is the second syntax required?
Sometimes the template parameters cannot be deduced from the function
call arguments (e.g. it is a return value, or internally used).
It might also be needed to resolve ambiguities.
Consider:
template<class T> T max(T a, T b);
sample uses:
double v;
std::cin >> v;
v = max( v, 0 ); // --> Error
v = max<double>( v, 0 ); // ok
v = max( v, 0.0 ); // ok
The notation is also handy when wanting to take the address of
the function:
myFuncPtr = & max<double>;
....
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <>
http://www.brainbench.com