template <class T>
class Stack // an abstract stack base class
{
public:
Stack() {}
virtual void pop() = 0; // all pure
virtual T top() const = 0;
virtual void push(const T& t) = 0;
virtual unsigned int size() const = 0;
};
template <class T>
class VStack : public Stack<T> // a vector-based implementation
{
private:
vector<T> vec;
public:
VStack() {}
void pop() { vec.pop_back(); }
T top() const { return vec[vec.size() - 1];}
void push (const T& t) { vec.push_back(t);}
unsigned int size() const { return vec.size(); }
};

How do call these method into the main method?

What doesn't work with this:

int
main()
{
  VStack<double> A;
  A.push(10.0);
  std::cout<<"A =="<<A.size()<<std::endl;
}

You remember that you have to use a template type in declaring VStack and that you might need to explicitly initialize the template if VStack and Stack are in separate files e.g. Add

template class Stack<double>;
template class VStack<double>;

HOWEVER: you may have made a complete mess, because you seem to have using namespace std; in your code, your names stack, etc are very close to the std names and you could easily be having real problems there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.