Erreur d'appel au constructeur
Bonjour
je rencontre un probleme dans mon code :
Premier fichier le header: Etudiant.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
| #ifndef ETUDIANT_H_INCLUDED
#define ETUDIANT_H_INCLUDED
#include <iostream>
#include <string>
//Class Etudiant
class Etudiant
{
public :
//Constructeur par défaut
Etudiant();
//Constructeur avec parametres pour la surcharge
Etudiant(std::string e_Nom,std::string e_Prenom,int e_Age);
//Detructeur
~Etudiant();
std::string afficherNom();
std::string afficherPrenom();
int afficherAge();
private:
//Attributs
std::string m_nom;
std::string m_prenom;
int m_age;
};
#endif // ETUDIANT_H_INCLUDED |
Fichier Etudiant.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
| #include <iostream>
#include <string>
#include "Etudiant.h"
using namespace std;
//Etudiant constructeur par défaut
Etudiant::Etudiant()
{
m_nom = "";
m_prenom= "";
m_age = 0;
}
//Etudiant avec surcharge du constructeur
Etudiant::Etudiant(string e_Nom,string e_Prenom,int e_Age):m_nom(e_Nom),m_prenom(e_Prenom),m_age(e_Age)
{
}
//Destructeur
Etudiant::~Etudiant()
{
}
//Afficher le nom
string Etudiant::afficherNom()
{
return m_nom;
}
//Afficher le prenom
string Etudiant::afficherPrenom()
{
return m_prenom;
}
//Afficher l'age
int Etudiant::afficherAge()
{
return m_age;
} |
Fichier main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| #include <iostream>
#include <string>
#include "Etudiant.h"
using namespace std;
int main()
{
//On crée un objet personne
Etudiant Personne;
Personne.Etudiant("toto","lele",40);// ici j'ai un message d'erreur : Invalid use of Etudiant::Etudiant
return 0;
} |
Merci d'avance pour votre aide
Bernard