TITLE: template name as a type name (Newsgroups: comp.lang.c++.moderated, 5 Oct 97) NAYAL: Murad Nayal >Is there any trick where i could use a template name as a type name i.e. > >template class A { //details omitted }; > >void func(A a_obj); > >so that func can take all T types of A. CLAMAGE: stephen.clamage@eng.Sun.COM (Steve Clamage) You can't use a template name as a type name, because a template is not a type, and a name in a given scope cannot refer to both a type and a template. You can use a typedef to refer to a particular instantiation of a template: typedef A Aint; void func(Aint& a_obj) { ... } But in your example you wanted the function to accept any instantiation of template A. That isn't possible, because a function parameter must be of one declared type. (You could use an ellipsis to indicate an argument of any type, but then you wouldn't know the type of the argument inside the function.) To get the effect you want, func needs to be a template as well: template< class T > void func(A a_obj) { ... } I know you said you didn't want to to that. I believe the only other option is to write an overloaded vesion of func for each A of interest: void func(A a_obj) { ... } void func(A a_obj) { ... } void func(A a_obj) { ... } ... etc ... I doubt that this is a practical solution. KANZE: kanze@gabi-soft.fr (James Kanze) Wouldn't the obvious solution be to derive the template class A from a non-template class, and define the function to take a reference to it, e.g.: template< class T > class A : public BaseA { ... } ; void f( BaseA const& obj ) ; In this case, whatever f needed to do with A should, of course, be defined as a pure virtual function in BaseA.