Analysis of C++ function template and Class template
This article introduces the knowledge of "C++ function template and class template analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Function template
The function template defines parameterized non-member functions, which allows programmers to call the same function with different types of arguments, and the compiler decides which type to call, and generates the corresponding code from the template.
Definition:
Template < Type Parameter Table > returns the type function name (formal parameter table) {function body}
Simple examples, call functions to print strings or numbers, etc.
In the form of ordinary functions:
# include # include void printstring (const std::string& str) {std::cout