Ok this is so bloody simple that it hurts me that I’m asking. I’m getting "error C2259: 'AdapterStack<T>' : cannot instantiate abstract class"
The three files are:
StackTest.cpp
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>// needed or cin, cout, endl are undefined
//#include "Stack.h"
#include "AdapterStack.h"
usingnamespace std;
usingnamespace std;
void main()
{
AdapterStack<string> stack1; //This is the line erroring out
}
#ifndef _ADAPTERSTACK_H
#define _ADAPTERSTACK_H
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "Stack.h"
usingnamespace std;
template <typename T>
class AdapterStack : public Stack<T> {
public:
AdapterStack();
~AdapterStack();
bool empty() const;
T push(T item);
T pop();
//T peek() const; //this line was causing another error too but its comment out at the moment.
};
template <typename T>
AdapterStack<T>::AdapterStack(){
}
#endif
That’s it. There isn’t anymore to this program at the moment. I know its something fundamental but none of my reference books are helping and I can’t find a good example online. What I’m having a hard time rapping my brain around is having a class be both Abstract and a Template. I fairly positive that the fact Stack.h is a template little to do with this but I’m weak enough in the subject that I’m second guessing everything.
Ok so I fixed some of the obvious. The issue I was having with the peek() function was that I didn’t have any of the method defined. So now they all are but now I’m getting “error C4430: missing type specifier - int assumed. Note: C++ does not support default-int” I get one for each method.