TITLE: function templates without as return value or parameter (Newsgroups: comp.lang.c++, 17 Jun 99) JELLE: Jelle (jelle@davilex.nl) wrote: : I want to be able to write a function template that does not : have as a return value or parameter. KUEHL: Dietmar Kuehl You mean something like this: template void allocate(int sz) { // do whatever is appropriate } int main() { allocate(17); allocate(17); } This is perfect standard C++ and I'm using it all the time (I'm using egcs but I know that this als supported at least by all EDG basied compiers and it is indeed standard C++). Only for member functions the calling syntax is ugly: struct foo { template void bar() {} }; int main() { foo f; f.template bar(); f.template bar(); } This feature is even used by one of the standard C++ functions, namely by 'std::use_facet()' (although this function returns a const reference to the argument but this actually does not matter because template parameters cannot be inferred from the return type). A work-around I used quite a while because feature was only relatively recently added to the standard and thus is implemented only since quite recently was a template class with an appropriate constructor and, if the function has to return a value, an appropriate conversion operator. I achieved to use the standard syntax of 'use_facet' for compilers which do not support explicitly specified template arguments this way (I have created an implementation of the IOStream and locale library and wanted to use the correct syntax): template struct use_facet { use_facet(locale const& l): facet(l.find_facet(Facet::id)) {} operator Facet const& () const { return facet: } private: Facet const& facet; }; (the real implementation looked somewhat different to cope with some other requirements, namely the possibility to call member functions on the result of use_facet using eg. 'use_facet<...>(l).truename()', but this is about it). You can use the same for your 'Allocate' function if your compiler does not yet support explicitly specified template arguments. Alternatively you might want to get a reasonable compiler...