I'm having compilation errors & need help on how to write my methods.
#include <iostream>
#include<string>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
template<class T>
class Stack{
public:
Stack();
//Requires: nothing.
//Effects: returns whether a stack is empty or not.
template <class T> bool empty();
//Method 1.1
//Requires: passing the constant item by &reference.
//Effects: adds item to the stack.
void push(const T& item);
//Method 1.2
//Requires: passing the non-constant item by &reference.
//Effects: adds item to the stack.
void push(T& item);
//Method 2
//Requires: nothing.
//Effects: returns the item most recently added to the stack.
T& top();
//Method 3
//Requires: nothing.
//Effects: removes the item most recently added to the stack.
void pop();
private:
vector<T> stack;
};
template <class T> Stack<T>::Stack() { }
template <class T> Stack<T>::empty(){ return stack.empty()}
int main(){
}
These are the compilation errors I'm getting:
prototype for 'int Stack::empty()' does not match any in class 'Stack' Stack::empty(){ }
stack.v.cpp:16:29: error: candidate is: template template bool Stack::empty() template bool empty();