How do I use temp in C? I would like to search for someone on this issueProbably misremembered the C++ template, because there is no word temp in the C keyword, if you don't believe it, you can check the details of the 32 keywords in the C language below:
The details of the keywords for C++ are as follows:
Only template has a character resemblance to temp.
In C++, the template keyword is used for declarationsProgram templates, which is specifically divided into:Function templateswithClass templates。The purpose of the program template is:Functions with similar aggregation functions and different data types are integrated to form a functional frameworkWhen a program template is executed, its actual function will be determined based on the parameters actually passed.
The declaration definition format for function templates and class templates is as follows:
1. Function template
Follow the order from simple to complex, and learn how to use template functions in C++ first.
For ease of understanding, the function template is defined using a simple summation operation. Since I have defined two types in the type form parameter table, the data types that are supported and manipulated in the C++ syntax can be passed as parameters, but it should be noted that the data width of parameter 2 must be greater than the data width of parameter 1 to ensure that the result of the operation does not overflow. If you want to perform operations on the same type of data in a function instance, you only need to define the type form parameter table as a type.
2. Class templates
Next, let's take a look at how C++ defines claims and uses class templates, as shown below
In this case, the class template declares a constructor and two ordinary member functions, one of which is returned using the second type in the formal argument table. The use of class templates, compared to normal classes, isThere is an additional use of angle brackets to specify specific data typesI believe that this way of writing must be familiar to people who are also learning j**a.
For more knowledge points about program templates in C++ programming, please explore them by yourself if you are interested, and we will not expand them here.