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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.