2 of 4
deleted 1 characters in body
BugShotGG
  • 211
  • 2
  • 8

There is a difference between function template and template function.

template<class Type>
void Foo(Type tData) {...}

if you wanted to pass int to function template Foo, but you also wanted the compiler to instantiate it as if it was passed a double you would call:

Foo<double> ( 12 );

Which instantiates the following template function:

void Foo(double);

With this special syntax Foo<>(), you are demanding compiler to instantiate Foo function for the type being explicitly passed, and asking the compiler not to deduce type by function argument.

A function template is body of a function that is bracketed around template keyword, which is not an actual function, and will not be fully compiled by compiler, and is not accountable by the linker. At least one call, for particular data-type(s) is needed to instantiate it, and be put into accountability of compiler and linker. Therefore, the instance of function template Foo is instantiated as Foo(int) or Foo(double).

A template function is simply an "instance of a function template", which is produced when you call it, or cause it to get instantiated for particular data type. The instance of function-template is actually a valid function.

An instance of a function template (aka template-function) is not a normal function, under the umbrella of name-decoration system of compiler and linker. That means, an instance of function-template:

template<class T> 
void Foo(T data) {...}

for template argument double, it is not:

void Foo<double>(double x) {...}

but actually:

void Foo<double>(double x) {...}

You can read more here:

Template terms

Template Tutorial

BugShotGG
  • 211
  • 2
  • 8