Nesting in a Template
You’ve seen that templates are a good choice for implementing container classes such as the Queue class. You may be wondering whether having a nested class poses any problems to converting the Queue class definition to a template. The answer is no. Listing 15.5 shows how this conversion can be made. As is common for class templates, the header file includes the class template, along with method function templates.
Listing 15.5. queuetp.h
// queuetp.h -- queue template with a nested class#ifndef QUEUETP_H_#define QUEUETP_H_template <class Item>class QueueTP{private: enum {Q_SIZE = 10}; // Node is a nested class definition class Node { public: Item item; Node * next; Node(const Item & i):item(i), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access