What is the difference between function template and template function?

后端 未结 4 766
难免孤独
难免孤独 2021-02-05 11:01

What is the difference between function template and template function?

相关标签:
4条回答
  • 2021-02-05 11:19

    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 (archive)

    0 讨论(0)
  • 2021-02-05 11:20

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

    Template Function is a colloquial synonym.

    So, there's no difference whatsoever.

    0 讨论(0)
  • 2021-02-05 11:35

    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.

    0 讨论(0)
  • 2021-02-05 11:39

    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

    0 讨论(0)
提交回复
热议问题