In our assignment it was given to us a stack class, this is the stack.h :
#ifndef STACK_H
#define STACK_H
#include "MyException.h"
#include <iostream>
using namespace std;
template<class T>
class Stack;
template<class T>
ostream& operator<<(ostream&,Stack<T>&);
template<class T>
class Stack
{
public:
/*The constructor for the Stack class*/
Stack();
/*The overloaded assignment operator. You will have to replace this
operator with an appropriate equivalent in your Java code*/
Stack<T>& operator=(const Stack<T>& other);
private:
/*The node class.*/
class Node
{
public:
Node(const T& data, Node* n = 0)
{
element = data;
next = n;
}
T element;
Node* next;
};
/*The top of the stack*/
Node* top;
};
#include "Stack.C"
#endif
And they gave us a Queue class, and this is the queue.h:
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
#include "MyException.h"
#include "Stack.h"
using namespace std;
template<class T>
class Queue;
/*The Queue class should be implemented in terms a of a Stack object.
Complete the Stack class first before attempting to implement this class.*/
template<class T>
class Queue
{
public:
/*The default constructor*/
Queue();
/*The copy constructor*/
Queue(const Queue<T>& other);
private:
/*You must store your elements in this stack*/
Stack<T>* stack;
};
#include "Queue.C"
#endif
So my problem is that I have implemented correctly the copy constructor in Stack.C but im not sure about how it should be done in Queue.C. I tried something but it gives me Segmentation fault. This is what I tried:
template<class T>
Queue<T>::Queue(const Queue<T>& other)
{
Stack<T> *test = new Stack<T>(*other.stack);
}
Can anyonw please help me solve this? Thank you