Je suis en train d'écrire un programme d'implémentation de pile et de file d'attente en c++, j'ai terminé la partie pile, mais lors de la compilation j'obtiens ces erreurs
arrayListImp.cpp:18:19: error: expected unqualified-id
arrayList[++top]= x;
^
arrayListImp.cpp:28:13: error: 'arrayList' does not refer to a value
itemPoped=arrayList[top];
^
./arrayList.h:3:7: note: declared here
class arrayList{
^
arrayListImp.cpp:35:9: error: 'arrayList' does not refer to a value
return arrayList[top];
^
./arrayList.h:3:7: note: declared here
class arrayList{
^
arrayListImp.cpp:46:9: error: 'arrayList' does not refer to a value
cout<<arrayList[i]<<endl;
^
./arrayList.h:3:7: note: declared here
class arrayList{
^
4 errors generated.
Voici le fichier d'en-tête
#ifndef ARRAYLIST_H
class arrayList{
public:
arrayList();
static const int maxSize = 10;
int array[10];
};
class stack : public arrayList{
public:
stack();
void push(int x);
void pop();
int Top();
int isEmpty();
void print();
int x;
int top;
int itemPoped;
int i;
};
#define ARRAYLIST_H
#endif
arrayListImp.cpp
#include <iostream>
#include "arrayList.h"
using namespace std;
//Stack implementation
stack::stack(){
top = -1;
}
void stack::push(int x){
if (top == maxSize -1){
cout<<"Stack overflow"<<endl;
}
else{
arrayList[++top]= x;
cout<<x<<", is pushed on to the stack"<<endl;
}
}
void stack::pop(){
if (top == -1){
cout<<"Stack underflow"<<endl;
}
else{
itemPoped=arrayList[top];
top--;
cout<<itemPoped<<", is poped from the stack"<<endl;
}
}
int stack::Top(){
return arrayList[top];
}
int stack::isEmpty(){
if (top == -1) return 1;
return 0;
}
void stack::print(){
cout<<"Stack: "<<endl;
for (i = 0; i<=top; i++){
cout<<arrayList[i]<<endl;
}
}
arrayListUse.cpp
#include <iostream>
#include "arrayList.h"
using namespace std;
int main()
{
//Stack testing
stack S;
S.push(1);S.print();
S.push(2);S.print();
S.push(3);S.print();
S.pop();S.print();
S.push(4);S.print();
//Queue testing
return 0;
}
Pouvez-vous m'indiquer ce que je fais de travers ?