Problem with Vector<pair<type,type>>

Joined
Mar 30, 2008
Messages
1
Reaction score
0
I compile this .cpp file in the dev-c++ environment,but I got the following error. Hope some one will help me.

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);

}
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
 
Joined
May 4, 2008
Messages
1
Reaction score
0
Problem with vector declaration

Not sure if you're still needing an answer to your problem, but I came across the same problem today and figured i'd post the answer.

When you declare your vector,

Code:
typedef vector<pair<T,T>> stacktype;

some compilers will choke with the <pair<T,T>> part because it wants it the have a space between the two >.

For example:

Code:
typedef vector<pair<T,T> > stacktype;

instead of

Code:
typedef vector<pair<T,T>> stacktype;


So I would suggest going through and putting a space anywhere you have >> to make it > >.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top