Changes between Version 2 and Version 3 of code/Template
- Timestamp:
- Apr 12, 2017, 10:29:54 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/Template
v2 v3 3 3 == Description == 4 4 5 A [wiki: template] is a class with an undefined type anywhere in it (for example a member variable, a function parameter or return value or even an undefined parent class). This undefined type gets replaced by a symbol. We'll usually use T as the symbol. Of course it's also possible to have more than one undefined type.5 A [wiki:Template] is a class with an undefined type anywhere in it (for example a member variable, a function parameter or return value or even an undefined parent class). This undefined type gets replaced by a symbol. We'll usually use T as the symbol. Of course it's also possible to have more than one undefined type. 6 6 7 Possible applications for templates are: Generic lists that can store ints or strings or !MyClasses or other lists, a container that stores an element of a specific class, a [wiki: Factory], a stream and many more.7 Possible applications for templates are: Generic lists that can store ints or strings or !MyClasses or other lists, a container that stores an element of a specific class, a [wiki:doc/Factory], a stream and many more. 8 8 9 9 Because the exact specifications of templates aren't defined, the compiler can't just compile the template once. In fact the template gets compiled once in every source that uses the template. That's why it's not possible to just include the header file of a template. You always have to include the source too. This is why programmers usually write the whole code of the template into the header file.