bonjour les amis, il ya une faute au niveau de l'operateur << pour chaque classe , aide svp :(
#include <iostream.h>
class basepile{
public:
int *p,taille;
basepile(int);
basepile(basepile&);
virtual void operator<(int);
virtual void operator>(int&);
virtual void affiche();
friend ostream& operator<<(ostream&,const basepile&);
~basepile();
};
class lifo:public basepile{
public:
int sommet;
lifo(int);
lifo(lifo&);
virtual void operator<(int);
virtual void operator>(int&);
virtual void affiche();
friend ostream &operator<<(ostream&,const lifo&);
};
class fifo:public basepile{
public:
int tete,que;
fifo(int);
fifo(fifo&);
virtual void operator<(int);
virtual void operator>(int&);
virtual void affiche();
friend ostream &operator<<(ostream&,const fifo&);
};
basepile::basepile(int n=10)
{taille=n;
p=new int[taille];}
basepile::basepile(basepile& a)
{taille=a.taille;
p=new int[taille];
for(int i=0;i<taille;i++)
p[i]=a.p[i];
}
basepile::~basepile(){delete []p;}
void basepile::operator<(int x)
{*p=x;}
void basepile::operator>(int &x)
{x=*p;}
void basepile::affiche(){
for(int i=0;i<taille;i++)
cout<<p[i];
}
ostream& operator<<(ostream&sortie,const basepile&a)
{
for(int i=0;i<a.taille;i++)
sortie<<a.p[i];
return sortie;
}
lifo::lifo(int n=10):basepile(n)
{sommet=0;}
lifo::lifo(lifo&a)
{
sommet=a.sommet;
taille=a.taille;
p=new int[taille];
for(int i=0;i<sommet;i++)
p[i]=a.p[i];
}
void lifo::operator<(int x)
{p[sommet]=x;
sommet++;
}
void lifo::operator>(int &x)
{sommet--;
x=p[sommet];
}
void lifo::affiche(){
for(int i=0;i<sommet;i++)
cout<<"\n"<<p[i];
}
ostream& operator<<(ostream&sortie,const lifo&a)
{
for(int i=0;i<a.sommet;i++)
sortie<<a.p[i];
return sortie;
}
fifo::fifo(int n=10):basepile(n){
que=0;
tete=0;
}
fifo::fifo(fifo&a){
que=a.que;
tete=a.tete;
taille=a.taille;
p=new int[taille];
for(int i=tete;i<que;i++)
p[i]=a.p[i];
}
void fifo::operator<(int x)
{p[que]=x;
que++;
}
void fifo::operator>(int &x)
{x=p[tete];
tete++;
}
void fifo::affiche(){
for(int i=tete;i<que;i++)
cout<<"\n"<<p[i];
}
ostream& operator<<(ostream&sortie,const fifo&a)
{
for(int i=a.tete;i<a.que;i++)
sortie<<a.p[i];
return sortie;
}
void main()
{basepile *ptpile;
fifo fifo1;
lifo lifo1;
ptpile=&fifo1;
*ptpile<1;
*ptpile<2;
*ptpile<3;
int i;
ptpile->affiche();
*ptpile>i;
cout<<"\ndepiler i="<<i<<"\n";
cout<<ptpile;
ptpile->affiche();
}