Topic: function parameter list must use template
Author: Stephen.Clamage@eng.sun.com (Steve Clamage)
Date: 1997/04/05 Raw View
In article 4ECC@statestreet.com.---, kv <vkrishnamurthy@statestreet.com.---> writes:
>
>This is in regards to function templates. Some compilers flag
>it as an error if the function parameter list does not use all
>the template parameters.
>
>I have browsed thru the CD2 and have not found this to be a
>requirement !
>
>On contemplation, though, I find this justified. Else, we have
>two cases
>
>1. the compiler instantiates this function for all the classes
>it knows about,
>
>2. the programmer has to instantiate before s/he uses this function
>
>These issues do not seem to be addressed by the CD.
>
>Can someone set me on the right track?
The original rule for function templates was that each template
parameter must be used in the parameter list. Example:
template< class T > void foo() { cout << typeid(T).name(); }
int main() { foo(); }
What should this program print? There is no way to decide what type
to use for T in any instantiation of function foo.
Recently the draft standard was changed, introducing a new syntax
for calling template functions. A call of a template function may
supply the actual types to be used in the same way as for
instantiations of template classes. In particular, if a template
parameter is not used in the function parameter list, you must
supply it in the call. Example:
int main() { foo<short>(); }
The template for function foo is instantiated with T meaning type short.
Not all compilers implement the new rules yet.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]