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), ...

Get C++ Primer Plus now with O’Reilly online learning.

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