Coder une liste chaînée d'objets.
Bonjour,
Je suis en train de bosser sur un exercice de Vasiliu C++, (sa solution est en C)
Je ne sais pas comment coder le pointeur sur objet pour lui passer l'adresse de l'objet suivant.
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
|
class PodeMother{
int Pode_data;
public:
PodeMother( int initial_n );
~PodeMother();
void printPode_data( void );
PodeMother* next;
};
/* L I B */
PodeMother::PodeMother( int initial_n ) {
Pode_data = initial_n;
cout << "Constructor de PodeMother\n";
}
PodeMother::~PodeMother() {
cout << "Destructor de PodeMother\n";
}
void PodeMother::printPode_data( void ){
cout << "Valeur de Pode_data :\t" << Pode_data << "\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
int dummy = 0;
PodeMother pd1( 43 );
pd1.printPode_data();
pd1.next = NULL;
// il faudrait assigner l'adresse du nouvel objet à un nouveau pointeur appartenant à l'objet père.
pd1.next = new PodeMother( 666 );
pd1.printPode_data();
cout << "\nFIN DU PROGRAMME: ENTREZ UN ENTIER S.V.P.: ";
cin >> dummy;
return 0;
} |
1) Je voulais l'appeler node_mother, mais VSC++ insiste pour mettre le tilde sur le N ---> Ñ (El Destructor)
2) printPode_Data affiche deux fois 43.
Merci si vous avez une réponse.:D