Une classe contenant un pointeur sur elle même
Bonsoir,
J'ai une classe Papier qui a comme attribut un pointeur sur un Papier. Seulement le compilateur me crie dessus et je ne comprend pas pourquoi :(
le .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
| /***********************************************************************
* Module: Papier.h
* Author: Scary
* Modified: mardi 30 mars 2010 13:15:22
* Purpose: Declaration of the class Papier
***********************************************************************/
#ifndef PAPIER_H
#define PAPIER_H
#include "TypePapier.h"
#include "EtatPapier.h"
class Papier
{
private:
Papier *papierFinal;
TypePapier typePapier;
EtatPapier etatPapier;
public:
Papier ();
Papier (TypePapier typePapier, EtatPapier etatPapier, Papier papierFinal);
Papier (const Papier& oldPapier);
virtual ~Papier();
virtual TypePapier getTypePapier (void) const;
virtual EtatPapier getEtatPapier (void) const;
virtual Papier getPapierFinal (void) const;
virtual void setPapierFinal (Papier newPapierFinal);
virtual void setTypePapier (TypePapier newTypePapier);
virtual void setEtatPapier (EtatPapier newEtatPapier);
};
#endif |
le .cpp
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| /***********************************************************************
* Module: Papier.cpp
* Author: Scary
* Modified: mardi 30 mars 2010 13:15:22
* Purpose: Implementation of the class Papier
***********************************************************************/
#include "Papier.h"
////////////////////////////////////////////////////////////////////////
// Name: Papier::Papier()
// Purpose: Implementation of Papier::Papier()
// Return:
////////////////////////////////////////////////////////////////////////
Papier::Papier()
{
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::Papier(TypePapier typePapier, EtatPapier etatPapier, Papier papierFinal)
// Purpose: Implementation of Papier::Papier()
// Parameters:
// - typePapier
// - etatPapier
// - papierFinal
// Return:
////////////////////////////////////////////////////////////////////////
Papier::Papier(TypePapier typePapier, EtatPapier etatPapier, Papier papierFinal)
{
// TODO : implement
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::Papier(const Papier& oldPapier)
// Purpose: Implementation of Papier::Papier()
// Parameters:
// - oldPapier
// Return:
////////////////////////////////////////////////////////////////////////
Papier::Papier(const Papier& oldPapier)
{
papierFinal = oldPapier.papierFinal;
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::~Papier()
// Purpose: Implementation of Papier::~Papier()
// Return:
////////////////////////////////////////////////////////////////////////
Papier::~Papier()
{
// TODO : implement
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::getTypePapier() const
// Purpose: Implementation of Papier::getTypePapier()
// Return: TypePapier
////////////////////////////////////////////////////////////////////////
TypePapier Papier::getTypePapier(void) const
{
// TODO : implement
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::getEtatPapier() const
// Purpose: Implementation of Papier::getEtatPapier()
// Return: EtatPapier
////////////////////////////////////////////////////////////////////////
EtatPapier Papier::getEtatPapier(void) const
{
// TODO : implement
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::getPapierFinal() const
// Purpose: Implementation of Papier::getPapierFinal()
// Return: Papier
////////////////////////////////////////////////////////////////////////
Papier Papier::getPapierFinal(void) const
{
return this->papierFinal;
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::setPapierFinal(Papier newPapierFinal)
// Purpose: Implementation of Papier::setPapierFinal()
// Parameters:
// - newPapierFinal
// Return: void
////////////////////////////////////////////////////////////////////////
void Papier::setPapierFinal(Papier newPapierFinal)
{
papierFinal = newPapierFinal;
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::setTypePapier(TypePapier newTypePapier)
// Purpose: Implementation of Papier::setTypePapier()
// Parameters:
// - newTypePapier
// Return: void
////////////////////////////////////////////////////////////////////////
void Papier::setTypePapier(TypePapier newTypePapier)
{
// TODO : implement
}
////////////////////////////////////////////////////////////////////////
// Name: Papier::setEtatPapier(EtatPapier newEtatPapier)
// Purpose: Implementation of Papier::setEtatPapier()
// Parameters:
// - newEtatPapier
// Return: void
////////////////////////////////////////////////////////////////////////
void Papier::setEtatPapier(EtatPapier newEtatPapier)
{
// TODO : implement
} |
Et l'erreur du compilo:
Code:
1 2 3 4 5
| Papier.cpp(89): error C2664: 'Papier::Papier(const Papier &)' : cannot convert parameter 1 from 'Papier *const ' to 'const Papier &'
1> Reason: cannot convert from 'Papier *const ' to 'const Papier'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>Papier.cpp(102): error C2440: '=' : cannot convert from 'Papier' to 'Papier *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called |
Si quelqu'un aurait une idée :( Merci d'avance :)