1. when the template definition and declaration are placed in the hpp file and cpp file respectively, a link error occurs. There are three ways to solve this problem: 1) Add # include "at the end of the hpp file. hpp "2) in # include ". # include ". cpp "3) do not place the cpp file and define it under hpp. 2. typename has two functions in the template. One is placed behind the template, indicating that the latter is a template parameter, and the other is typename indicating to reference the type in the template class, such as typename T: type *; this definition indicates that type is defined in the T type. If typename is not added, type × a; 3 is used. template parameters. The template parameters include type parameters, non-type parameters, and template parameters. The types of non-type parameters include integer, enumeration type, pointer type, and reference type. Float and character types are not supported. Example: type parameter template <typename T> T max (const T & a, const T & B) {return a> B? A: B;} non-type parameter template <typename T, int value> T addvalue (T const & a) {return a + value;} template parameter template <typename T, template <typename T2, typename T3> class T4> class test {}; 4. the template is special and instantiated. The instantiation of a biased template refers to the process in which a template class or template function is used to obtain a specific class or function. The template specialization refers to the final entity obtained. The feature can add member variables or member functions to a class. The feature defines that a class can better adapt to the specific type. For example, when I define a bird, because the penguin is also a bird, but it will not fly, then when I become a penguin, I can redefine the method of flying the bird. 5. There is no direct relationship between the template and the inline template. to define an inline function, you must add inline or implicit inline before the function name. 6. the member functions and virtual functions of the template and virtual function classes are mutually exclusive. If they are defined as virtual functions, they cannot be defined as template functions, if it is defined as a template function, it cannot be defined as a virtual function. 7. Explicit instantiation by default, the compiler will generate various types of instances. To reduce the cost, the compiler can generate several types of instances, that is, explicitly telling the compiler to instantiate several types. During explicit instantiation, an instance can only be explicitly instantiated once, and multiple types can be explicitly instantiated. For example, template max <int> (int const & a, int const & B );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.