One of my homework assignments is to create a hierarchy of Stack and Queue. I am required to have a superclass DataStructure
which has member functions push and pop. pop is supposed to be declared only once within DataStructure
while push is required to be a virtual function. This is what I have so far:
#include <iostream>
#include <vector>
using namespace std;
class DataStructure {
protected:
vector<int> data;
public:
void push(int element) { }
int pop() {
if (data.size() == 0)
return -1;
int elem = data.back();
data.pop_back();
return elem;
}
};
class Stack: public DataStructure {
};
class Queue: public DataStructure {
};
I am stuck. I do not know how to implement the virtual function.