Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function template or Gereric function is the right term?

Im kind of stuck on this. I read in a book that we can make Generic functions with function template but on other places, author called the generic function, an function template. witch is proper for example:

template <class T> void printSmt(T x){}

in here printSmt is called generic function or function template?

And another question: is x in parameter list of function printSmt a generic type or a template parameter?

EDIT: im writing some documents for my school. if it's possible give me an answer according to C++ reference.

like image 797
FrozenFrog Avatar asked May 14 '26 18:05

FrozenFrog


1 Answers

The C++ Standard calls it function template. The term generic function is more used in other object-oriented languages (e.g. in LISP these are functions with the same name). Java uses generic types to implement a minimal approach of generic programming.

x is the function parameter. T is the template parameter. In printSmt<int>() int is the template argument.

like image 132
TheSlayer Avatar answered May 17 '26 08:05

TheSlayer