Bonjour à tous !
Je suis débutant en programmation c++ et je me suis inscrit sur ce forum en espérant y recevoir un peu d'aide sur un problème dont je ne trouve pas de solution...
Voilà le topo : je dois créer une classe personne et une classe client qui en est dérivée (notions d'héritage). Un client est une personne.
Voici mon code :
Mon .h :
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
| #include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
///////////////////////////
// --------------------- //
// GESTION DES PERSONNES //
// --------------------- //
///////////////////////////
//Classe Personne
//---------------
class Personne
{
protected :
string nom;
string prenom;
string adresse;
string ville;
string pays;
string mail;
public :
Personne();
Personne(string no, string pr, string ad, string vi, string pa, string ma);
virtual void affiche();
~Personne();
};
//Classe Client
//--------------
class Client:public Personne
{
protected :
int numero;
public :
Client(int nu, string no, string pr, string ad, string vi, string pa, string ma);
virtual void affiche();
~Client();
}; |
Mon .cpp
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
| #include "projethotel.h"
//Classe Personne//
//---------------//
Personne::Personne(string no, string pr, string ad, string vi, string pa, string ma) : nom(no), prenom(pr), adresse (ad), ville (vi), pays (pa), mail (ma)
{
cout<<"Constructeur Personne"<<endl;
}
void Personne::affiche()
{
cout<<endl<<"Nom: "<<nom<<endl <<"Prenom:"<<prenom<<endl;
cout<<"Adresse: "<< adresse<< endl <<"Ville: "<<ville<<endl;
cout <<"Pays: "<<pays<<endl <<"Mail: "<<mail<< endl;
}
Personne::~Personne(){cout<<"Destructeur Personne"<<endl;}
//Classe Client//
//-------------//
Client::Client(int nu,string no, string pr, string ad, string vi, string pa, string ma) : numero(nu)
{
cout<<"Constructeur Client"<<endl;
}
void Client::affiche()
{
cout<<endl<<"Numero: "<<numero<<endl;
Personne::affiche();
}
Client::~Client(){cout<<"Destructeur Client"<<endl;} |
Et enfin mon main
1 2 3 4 5 6 7 8 9 10 11 12
| #include "projethotel.h"
void main ()
{
Personne p1("Durant","Marc","Dreve","Tournai","Belgique","dur32@hotmail.com"); //TEST
p1.affiche(); //D'AFFICHAGE Personne
Client c1(1,"Durant","Fred","Dreve","Tournai","Belgique","fredy@hotmail.com"); //TEST
c1.affiche(); //D'AFFICHAGE Client
system("pause");
} |
L'affichage de Personne fonctionne quand je mets en commentaire tout ce qui concerne ma classe Client.
Par contre, en ajoutant ma classe client, j'ai ce message d'erreur qui s'affiche à la compilation :
1>projethotel.obj : error LNK2019: symbole externe non résolu "public: __thiscall Personne::Personne(void)" (??0Personne@@QAE@XZ) référencé dans la fonction "public: __thiscall Client::Client(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Client@@QAE@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00000@Z)
HELP !!!
Partager