COMP 2404 Lecture Notes - Lecture 7: Orson Scott Card, Isaac Asimov, Include Directive
Document Summary
Function templates -> the goal is to create a function that works with any data type. If a member function is templated its class must be too. What the compiler does is it creates a specialisation of the template for each data type you use. We can overload templated functions with non-templated functions. Templated functions can be overloaded with same name but different parameters. Compiler gives preference to a non-templated function over templated one (that s the convention) Class templates -> the goal is to create a class that works with any data type. Any member function or data member can use that data type of the class. We can instantiate of that class using any data type. This is the first and the only time in this course we are breaking the rule of not implementing class implementations in the header file. Templates only work when implemented in the header file and not otherwise.