What is the difference between function template and template function?

跟風遠走 提交于 2019-12-03 06:19:44
Tim Sylvester

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".

From this FAQ.

Comeau Computing (maker of C++ Comeau Compiler) has a FAQ on their site with the answer to that question:

What is the difference between a template function and a function template?

Regards,
Ovanes

Function Template is the correct terminology (a template to instantiate functions from).

Template Function is a colloquial synonym.

So, there's no difference whatsoever.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!