[SURGHARGE][HERITAGE] Probleme compilation
Voilà, j'ai fais trois TP en C++ et le dernier me faisait travailler l'héritage et la surcharge.
Voici le main proposé en énoncé :
c_base_pile.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include "c_base_pile.h"
std::ostream& operator << (std::ostream&,const PileDeChar&);
int main(void)
{
PileDeChar* ptPile;
pileFIFO fifo;
pileLIFO lifo;
ptPile=&fifo;
*ptPile < '1' < 'A';
cout<<"pile1 = "<<*ptPile<<endl;
char i='3';
*ptPile > i;
cout<<"pile2 = "<<*ptPile<<", i = "<<i<<endl;
ptPile=&lifo;
*ptPile < '5' < 'C';
cout<<"pile3 = "<<*ptPile<<endl;
*ptPile > i;
cout<<"pile4 = "<<*ptPile<<", i = "<<i<<endl;
system("pause");
return 0;
} |
Partie que j'ai ajouté au main
Code:
1 2 3 4 5 6
|
std::ostream& operator << (std::ostream& flux, const PileDeChar& pile)
{
pile.Affichage(flux);
return flux;
} |
===========================================
Maintenant voici ce que j'ai écrit :
c_base_pile.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream.h>
class PileDeChar {
protected:
unsigned int mMax; /*Taille de la pile crée,num case libre*/
char *mPile; /*Tableau alloué dynamiquement*/
int mSommet;
public:
PileDeChar();
PileDeChar(signed int);
PileDeChar(const PileDeChar&);
~PileDeChar();
int CompterElements() const;
int LitmMax() const;
void AfficherPile() const;
bool EmpilerElem(char);
char RenvoiElement(signed int) const;
PileDeChar& operator < (char);
virtual PileDeChar& operator > (char&)=0;
friend std::ostream& operator << (std::ostream&, const PileDeChar&);
virtual void Affichage(std::ostream&) const;
};
class pileFIFO:public PileDeChar {
public:
virtual char DesempilerElem();
pileFIFO& operator > (char&);
virtual void Affichage(std::ostream&);
};
class pileLIFO:public PileDeChar {
public:
virtual char DesempilerElem();
pileLIFO& operator > (char&);
virtual void Affichage(std::ostream&);
}; |
c_base_pile.c :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream.h>
#include "c_base_pile.h"
PileDeChar::PileDeChar()
{
mMax=100;
mSommet=0;
mPile=new char[100];
cout<<"Construction effectuee !"<<endl;
}
PileDeChar::PileDeChar(signed int taille)
{
mMax=taille;
mSommet=0;
mPile=new char[taille];
cout<<"Construction effectuee !"<<endl;
}
PileDeChar::PileDeChar(const PileDeChar& copie)
{
size_t i=0;
mMax=copie.mMax;
mSommet=copie.mSommet;
mPile=new char[mMax];
while(i<mSommet)
{
mPile[i]=copie.mPile[i++];
}
cout<<" Copie Pile effectuee!"<<endl;
}
PileDeChar::~PileDeChar()
{
delete(mPile);
cout<<"Destruction effectuee !"<<endl;
}
int PileDeChar::CompterElements() const
{
if (mPile!=NULL)
return mSommet;
else return -1;
}
int PileDeChar::LitmMax() const
{
if (mPile!=NULL)
return mMax;
else return -1;
}
void PileDeChar::AfficherPile() const
{
size_t i=0;
if(mSommet==0)
cout<<"Il n'y a rien a afficher !"<<endl;
else
{
while(i<mSommet) cout<<"["<<mPile[i++]<<"] ";
cout<<endl;
}
}
char PileDeChar::RenvoiElement(signed int i) const
{
if ((mPile!=NULL)&&((i>=0)&&(i<LitmMax())))
return mPile[i];
else
{cout<<"ERREUR, PILE VIDE, MAUVAIS INDICE"<<endl;
return 0;}
}
bool PileDeChar::EmpilerElem(char elem)
{
bool reussi=false;
if(mSommet<LitmMax())
{
mPile[mSommet++]=elem;
reussi=true;
}
else
reussi=false;
return reussi;
}
PileDeChar& PileDeChar::operator<(char elem)
{
if(mSommet<LitmMax())
{
mPile[mSommet++]=elem;
}
return *this;
}
//void PileDeChar:: operator > (char a){cout<<"erreur"<<endl;}
void PileDeChar:: Affichage(std::ostream& flux) const
{
int i=0;
while(i<mSommet)
flux << mPile[i++];
} |
fifo.c :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream.h>
#include "c_base_pile.h"
char pileFIFO::DesempilerElem()
{
char temp;
int i=0;
if((mSommet>0)&&(mSommet<=LitmMax()))
{
temp=RenvoiElement(0);
while(i<mSommet)
{
mPile[i]=mPile[i+1];
i++;
}
mSommet--;
return temp;
}
else
{
cout<<"ERREUR : IL N'Y A RIEN A RECUPERER"<<endl;
return 'e';
}
}
pileFIFO& pileFIFO::operator > (char &a)
{
int i=0;
if((mSommet>0)&&(mSommet<=LitmMax()))
{
a=RenvoiElement(0);
while(i<mSommet)
{
mPile[i]=mPile[i+1];
i++;
}
mSommet--;
}
else
cout<<"ERREUR : IL N'Y A RIEN A RECUPERER"<<endl;
return *this;
}
void pileFIFO::Affichage(std::ostream& flux)
{
int i=0;
while(i<mSommet)
flux << mPile[i++];
cout<<"fifo"<<endl; /* ME PERMET DE SAVOIR QUELLE FONCTION AFFICHAGE EST APPELEE*/
} |
lifo.c :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream.h>
#include "c_base_pile.h"
char pileLIFO::DesempilerElem()
{
if((mSommet>0)&&(mSommet<=LitmMax()))
{
mSommet--;
return RenvoiElement(mSommet);
}
else
{
cout<<"ERREUR : IL N'Y A RIEN A RECUPERER"<<endl;
return 'e';
}
}
pileLIFO& pileLIFO::operator > (char &a)
{
if((mSommet>0)&&(mSommet<=LitmMax()))
{
mSommet--;
a=RenvoiElement(mSommet);
}
else
cout<<"ERREUR : IL N'Y A RIEN A RECUPERER"<<endl;
return *this;
}
void pileLIFO::Affichage(std::ostream& flux)
{
int i=0;
while(i<mSommet)
flux << mPile[i++];
cout<<"fifo"<<endl; /* ME PERMET DE SAVOIR QUELLE FONCTION AFFICHAGE EST APPELEE*/
} |
Mon problème est le suivant : aucune erreur sous DevC pp a priori. Mais des fois j'ai un warning qui apparait lors de la compilation(sans execution)(CTRL+F9) :
Citation:
3 F:\Dev-Cpp\projet\C++\tp3\c_base_pile.h [Warning] `class PileDeChar' has virtual functions but non-virtual destructor
28 F:\Dev-Cpp\projet\C++\tp3\c_base_pile.h [Warning] `class pileFIFO' has virtual functions but non-virtual destructor
.....
Et la si je recompile et lance le programme(F9) le warning disparrait et le programme fonctionne.
Voilà donc j'aimerais avoir votre avis éclairé sur mon programme. Merci d'avance.
PS : j'ai utilisé protected car je ne voulais pas faire de méthodes d'accés. Je sais que j'aurais du mais cette histoire d'héritage me tracassait...
Merci encore :)