What is the difference between function template and template function?
- 2Related: stackoverflow.com/questions/879535/…avakar– avakar2009-07-13 05:33:11 +00:00Commented Jul 13, 2009 at 5:33
- See Johannes answer to a similar question. He was enlightening. stackoverflow.com/questions/879535/…Ram– Ram2022-01-25 17:01:02 +00:00Commented Jan 25, 2022 at 17:01
3 Answers
The term "function template" refers to a kind of template. The term "template function" is sometimes used to mean the same thing, and sometimes to mean a function instantiated from a function template. This ambiguity is best avoided by using "function template" for the former and something like "function template instance" or "instance of a function template" for the latter. Note that a function template is not a function. The same distinction applies to "class template" versus "template class".
5 Comments
The function generated by the compiler from function template(generic function) for specified data type is known as template function. Example: The below code is called function template as it is template for a function.
template<T> T doubleVal(T a){ return a+a; } int main(){ cout<<doubleVal<int>(5)<<endl; } When we compile this code compiler will write a function for int by taking reference from template function. That function is known as template function.