PDA

Visualizza la versione completa : [C++]Stack


Luc@s
02-12-2003, 13:32
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

template<class T>
class Stack
{
public:
// Constructor with dimension
Stack(int dim) { vet = new T[checkDim(dim)]; };
// Constructor without dimension
Stack() { vet = new T[5]; };
// Check and verify the chosed dimensione
int checkDim(int dim) { return(dim <= 0)?5:dim; };
// The destructor
~Stack(){};
// add a element
void push(T value) { vet[sp++] = value; };
// return a element (and no delete)
T pop() { return vet[sp--]; };
// return a element (and delete)
T pop_d()
{
int index =sp--;
T tmp = vet[index];
delete vet[index];
return tmp;
};
private:
T vet;
int sp;
};
Mi da (riga in neretto):

P:/C++/stack/stack.h:21: invalid types `int[int]' for array subscript


Tnk 100000000000

ChReAn
02-12-2003, 14:06
Gcc compila tranquillamente. Che compilatore usi?

Luc@s
02-12-2003, 15:26
DevC++

xegallo
02-12-2003, 15:40
devc++ 4 lo compila

Luc@s
02-12-2003, 15:43
a me no :dottò:
E neanche VC++6..............stesso errore :fagiano:

Loading