In lecture today, the following topics were covered:
- definition of the data that compose the Node and LinkedList classes
- the core methods of the Node class (constructor, get/set data/next)
- friend classes
- templated classes - useful for building containers
- the LinkedList addFront operator
Example code will be posted soon for friend classes, templated classes, and LinkedList operations (as we reveal them).
Here is source code for a templated Node class: Node.h, Node.cpp, nodeMain.cpp, makefile
One detail we didn’t discuss, but which should hopefully make sense: notice in nodeMain.cpp that I #include Node.cpp (which itself brings in Node.h). Remember that templates are patterns - they are used to auto-generate code which is later compiled, and this only happens after main is scanned to see what type of templated Node is need (Node<int> triggers an integer based Node for example). The compiler has to see all of the Node definition (the variables and the method implementations) at the same time to auto-generate the code, so all of this is pulled into the main source code to be compiled.
Also note the friend « operator - it is templated itself, separately. You can think of this in simple terms as: since the « function is not actually a class member method, it is not handled by the class templating so it must be dealt with separately. One can also not reuse a template variable (T) within a templated section, so another variable is chosen (U).