The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Linked lists Object Methods for Nodes | ||
Object Methods for Nodes
In this case there is a legitimate reason to choose class methods. It is legal to send null as an argument to a class method, but it is not legal to invoke an object method on a null object. Node *node = null;printList (node); // legal node.printList (); // NullPointerException This limitation makes it awkward to write list-manipulating code in a clean, object-oriented style. A little later we will see a way to get around this, though.
|
||
Home Linked lists Object Methods for Nodes |