Item 50. Member Templates

Class templates have members that are not themselves templates, and many of these members can be defined outside the class. Let’s look at a singly linked list container:


The member functions of a template, when defined outside the class template, have a template header with the same structure as that used in the class template definition:

template <typename T>bool SList<T>::empty() const    { return head_ == 0; }

We’ve decided to implement our singly linked list as a pointer to a sequence of nodes, where each node contains a list element and a pointer to the next node on the list. (A more sophisticated implementation ...

Get C++ Common Knowledge: Essential Intermediate Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.