Can anyone help to explain this section of coding from a stack and queue program?
Such as adding some explained commenting for me to get a better understanding of what this code does.
template <typename T> //a template class is a generic design that allows you
//to insert any type. It is useful for containers, of course, so you can have a
//stack of int or double or your own class etc.
class Queue : protected Stack<T> //this class is the queue, it inherits from stack class (not seen).
{
private: //this is pointless, because class members are private by default.
Node<T> *pFront; //the queue class has a private node. Presumably a linked list type thingy, also not seen.
public: //the opposite of private, these variables and methods etc can be accessed by the user outside the class' internal functions.
Queue(void); //these are function prototypes; this class with define these "methods" or functions that tightly couple the class' data with functions that operate on the data.
//This one is the constructor, called when you create a variable of queue class type.
~Queue(void); //~ is the class destructor, called when a variable of the class type goes out of scope.
virtualvoid enqueue(T value); //presumably adds an item to your queue.
virtual Node<T>* nodeDequeue(void); //presumably removes item from queue.
virtual T dequeue(void); //a second way to remove from the queue somehow. also, note that virtual functions can be (re)written by the class user, and may not even have a body until the user writes one. It varies. Probably being overused here.
};
template<typename T> //function bodies.
void Queue<T>::enqueue(T value)
{
this->Push(value); //call some unseen function push
if (pFront == nullptr) pFront = pTop; //handle case of null pointer
//
else (pTop->pNext)->pPrevious = pTop; //handle normal case
}
template<typename T>
Queue<T>::Queue(void) //body for constructor. sets pointers to null.
{
pFront = pTop = nullptr;
}