Bonjour à tous
jai une classe étudiant qui hérite d'une classe personne ayant une méthode void ecrire(ostream&)const. Ma méthode écrire affiche une personne sous le format: Personne(nom, prenom). Je veux implémenter une méthode ecrire() dans la classe étudiant qui affiche un étudiant sous le format Etudiant(Personne(nom, prenom), Ine) et cela en me servant de la méthode ecrire de la classe personne comme suit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
void Etudiant::ecrire(ostream& os){
	os << "Etudiant("<< Personne::ecrire(ostream& os)<<","<<Ine<<")"<<endl;
mais jai l'erreur expected primary-expression before ‘&’ token et je c pas ski manque.

voici mes classes:
Personne.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef DEF_PERSONNE
#define DEF_PERSONNE
#include <string>
#include <iostream>
 
using namespace std;
 
class Personne
{
protected:
	string nom;
	string prenom;
public:
	Personne();
	Personne(string ,string);
	~Personne();
	void ecrire(ostream&)const;
 
	friend ostream & operator<<(ostream & os , Personne &P);
	friend istream & operator>>(istream & is, Personne &P);
};
#endif
Personne.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
 
#include "Personne.h"
 
using namespace std;
 
Personne::Personne():nom("inconnu"),prenom("inconnu"){
	cout<<"Personne::Personne()"<<endl;
}
 
Personne:: Personne(string nomRecu, string prenomRecu):nom(nomRecu),prenom(prenomRecu){
	cout<<"Personne:: Personne(String nom, String prenom)"<<endl;
}
 
Personne:: ~Personne(){
	cout<<"Personne::~Personne()"<<endl;
}
 
void Personne::ecrire(ostream& os) const {
 
	os<<"Personne("<<nom<<","<<prenom<<")"<<endl;
}
Etudiant.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef DEF_ETUDIANT
#define DEF_ETUDIANT
 
#include "Personne.h"
#include <string>
 
class Etudiant: public Personne
{
protected:
	std::string Ine;
public:
	Etudiant();
	Etudiant(string, string, string);
    	~Etudiant();
	void ecrire(ostream&);
 
	friend ostream & operator<<(ostream & os , Personne &P);
};
#endif
Etudiant.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "Etudiant.h"
 
using namespace std;
 
Etudiant::Etudiant():Ine("inconnu"){
	cout<<"Etudiant::Etudiant()"<<endl;
}
 
Etudiant::Etudiant(string nomRecu,string prenomRecu,string IneRecu):Personne(nomRecu,prenomRecu),Ine(IneRecu){
	cout<<"Etudiant de nom: "<<nom<<"\t et de prenom : "<<prenom<<"\t de numéro ine:"<<Ine<<endl;
}
 
Etudiant::~Etudiant(){
	cout<<"Etudiant::~Etudiant()"<<endl;
}
 
void Etudiant::ecrire(ostream& os){
	os << "Etudiant("<< Personne::ecrire(ostream& os)<<","<<Ine<<")"<<endl;
}
voilà!
je sais pas trop où ça cloche. Merci de bien vouloir m'aider ce serait gentil