I compile this .cpp file in the dev-c++ environment,but I got the following error. Hope some one will help me.
error:
main.cpp: 10:error: E:\project\Algorithm\main.cpp `stacktype' was not declared in this scope
main.cpp:10: error: `>>' should be `> >' within a nested template argument list
main.cpp:15: error: a function call cannot appear in a constant-expression
main.cpp:15: error: `&' cannot appear in a constant-expression
main.cpp:15: error: `>>' should be `> >' within a nested template argument list
main.cpp:16: error: declaration of `T stack<T>::min()'
main.cpp:12: error: conflicts with previous declaration `T stack<T>::min'
main.cpp:21: error: `Stack' was not declared in this scope
main.cpp:21: error: `&' cannot appear in a constant-expression
main.cpp:21: error: `>>' should be `> >' within a nested template argument list
main.cpp:21: error: expected init-declarator before '<' token
main.cpp:21: error: expected `;' before '<' token
main.cpp:36: error: `Stack' was not declared in this scope
main.cpp:36: error: `&' cannot appear in a constant-expression
main.cpp:36: error: `>>' should be `> >' within a nested template argument list
main.cpp:36: error: expected init-declarator before '<' token
main.cpp:36: error: expected `;' before '<' token
main.cpp:45: error: expected init-declarator before '<' token
main.cpp:45: error: expected `;' before '<' token
main.cpp:49: error: `main' must return `int'
main.cpp: In instantiation of `stack<int>':
main.cpp:50: instantiated from here
main.cpp:12: error: declaration of `T stack<T>::min() [with T = int]'
main.cpp:12: error: conflicts with previous declaration `int stack<int>::min'
make.exe: *** [main.o] Error 1
Code:
#include <vector>
#include <utility>
using namespace std;
template<class T>
class stack{
private:
typedef vector<pair<T,T>> stacktype;
stacktype stacker;
T min;
public :
vector< pair<T,T> >& pop();
vector<pair<T,T>>& push(const T& e);
T min();
};
template<class T>
vector<pair<T,T>>& Stack<T>::push(const T& e){
if(stack.empty())
{
min=e;
}
pair<T,T> node(e,min);
stack.pusk_back(node);
if(e<min){
min=e;
}
return stacker;
}
template<class T>
vector<pair<T,T>>& Stack<T>::pop(){
pair<T,T> node;
node=statck.back();
min=node.second();
stack.pop_back();
return stacker;
}
template<class T>
T Stack<T>::min(){
return min;
}
void main(){
stack<int> stackins;
for(int i=0;i<10;i++)
stackins.push(i);
}
main.cpp: 10:error: E:\project\Algorithm\main.cpp `stacktype' was not declared in this scope
main.cpp:10: error: `>>' should be `> >' within a nested template argument list
main.cpp:15: error: a function call cannot appear in a constant-expression
main.cpp:15: error: `&' cannot appear in a constant-expression
main.cpp:15: error: `>>' should be `> >' within a nested template argument list
main.cpp:16: error: declaration of `T stack<T>::min()'
main.cpp:12: error: conflicts with previous declaration `T stack<T>::min'
main.cpp:21: error: `Stack' was not declared in this scope
main.cpp:21: error: `&' cannot appear in a constant-expression
main.cpp:21: error: `>>' should be `> >' within a nested template argument list
main.cpp:21: error: expected init-declarator before '<' token
main.cpp:21: error: expected `;' before '<' token
main.cpp:36: error: `Stack' was not declared in this scope
main.cpp:36: error: `&' cannot appear in a constant-expression
main.cpp:36: error: `>>' should be `> >' within a nested template argument list
main.cpp:36: error: expected init-declarator before '<' token
main.cpp:36: error: expected `;' before '<' token
main.cpp:45: error: expected init-declarator before '<' token
main.cpp:45: error: expected `;' before '<' token
main.cpp:49: error: `main' must return `int'
main.cpp: In instantiation of `stack<int>':
main.cpp:50: instantiated from here
main.cpp:12: error: declaration of `T stack<T>::min() [with T = int]'
main.cpp:12: error: conflicts with previous declaration `int stack<int>::min'
make.exe: *** [main.o] Error 1