IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Liste triée de pointeurs intelligents


Sujet :

C++

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2013
    Messages : 25
    Points : 17
    Points
    17
    Par défaut Liste triée de pointeurs intelligents
    Bonjour à tous,

    Je dois pour l'école faire une application de gestion d'horaire dans laquelle est géré des cours.

    La classe cours hérite de la classe event,
    classe event:
    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
    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    #include "Event.h"
     
    Event::Event()
    {
    	Code = 0;
    	Intitule = NULL;
    	strcpy(Lieu, "0");
    	timing=new Timing();
    }
     
    Event::~Event()
    {
    	if(Intitule != NULL)
    		delete Intitule;
    	Intitule = NULL;
    }
     
    Event::Event(const int C, const char *I, const char *L ,const Timing &T)
    {
    	//cout << "Constructeur d'initialisation Event" << endl;
    	setCode(C);
    	setIntitule(I);
    	setLieu(L);
      	timing=new Timing(T);
    }
     
    Event::Event(const int C, const char *I, const char *L )
    {
    	//cout << "Constructeur d'initialisation Event" << endl;
     
    	Intitule = NULL;
    	timing=new Timing();
     
    	setCode(C);
    	setIntitule(I);
    	setLieu(L);
    }
     
    Event::Event(const Event &copie)
    {
    	setCode(copie.getCode());
    	setIntitule(copie.getIntitule());
    	setLieu(copie.getLieu());
    	setTiming(copie.getTiming());
    }
     
    int Event::getCode()const
    {
    	return Code;
    }
     
    char *Event::getIntitule()const
    {
    	return Intitule;
    }
     
    char *Event::getLieu()const
    {
    	return (char *)Lieu;
    }
     
    Timing &Event::getTiming()const
    {
    	return *timing;
    }
    void Event::setCode(const int code)
    {
    	//cout << "SetCode Event" << endl;
     
    	Code = code;
    }
     
    void Event::setIntitule(const char *I)
    {
    	//cout << "SetIntitule Event" << endl;
    	if(Intitule)
    		delete Intitule;
     
    	if(I)
    	{
    		Intitule = new char[strlen(I)+1];
    		strcpy(Intitule, I);
    	}
    	else
    		Intitule = NULL;
    }
     
    void Event::setLieu(const char lieu[] )
    {
    	//cout << "SetLieu Event" << endl;
    	if(strlen(lieu) <= 21)
    		strcpy(Lieu, lieu);
    	else
    		strcpy(Lieu, "");
    }
     
    void Event::setTiming(const Timing &t)
    {
    	//cout << "SetTiming Event" << endl;
     
    	timing = NULL;
    	timing = new Timing(t);
    	/*timing->setJour(t.getJour());
    	timing->setHeure(t.getHeure());
    	timing->setDuree(t.getDuree());*/
    }
    void Event::Affiche()const
    {
    	cout << "Code: " << getCode() << endl;
    	if(Intitule)
    	{
    		cout << "Intitule: " << Intitule << endl;
    	}
    	cout << "Lieu: " << Lieu << endl;
    }
     
    ostream& operator<< (ostream& flux, const Event &P)
    {
    	/*if(P.getNom() && P.getPrenom())
    	{
    		flux << "Nom: " << P.getNom() << endl;
    		flux << "Prenom: " << P.getPrenom() << endl;
    	}*/
    	return flux;
     
    }
    istream& operator>> (istream& flux, Event &P)
    {
    	int Code;
    	char *Intitule = new char[50];
    	char Lieu[21];
    	Timing timing;
     
    	cout << "Code: ";
    	flux >> Code;
    	cout << "Intitule: ";
    	flux >> Intitule;
    	cout << "Lieu: ";
    	flux >> Lieu;
    	flux >> timing;
     
    	P.setCode(Code);
    	P.setIntitule(Intitule);
    	P.setLieu(Lieu);
    	P.setTiming(timing);
     
    	return flux;
    }
     
    Event & Event::operator=(const Event &e)
    {
     
    }
     
    bool Event::operator==(const Event &e)
    {
     
    }
     
    bool Event::operator>(const Event &e)
    {
     
    }
     
    bool Event::operator<(const Event &e)
    {
     
    }
     
    void Event::Save(ofstream &fichier)const
    {
    	int TailleInt = strlen(getIntitule());
    	int code = getCode();
     
    	fichier.write((char *) &code, sizeof(int));
    	fichier.write((char *)&TailleInt, sizeof(TailleInt));
    	fichier.write((char *)getIntitule(), TailleInt*sizeof(char));
    	fichier.write((char *)getLieu(), sizeof(Lieu));
     
    	timing->Save(fichier);
    }
    void Event::Load(ifstream &fichier)
    {
    	int TailleInt, code;
    	char *Int;
    	char lieu[sizeof(Lieu)];
     
    	fichier.read((char *) &code, sizeof(int));
    	fichier.read((char *) &TailleInt, sizeof(int));
    	Int = new char[TailleInt];
    	fichier.read((char *) Int, TailleInt);
    	fichier.read((char *) &lieu, sizeof(Lieu));
     
    	setCode(code);
    	setIntitule(Int);
    	setLieu(lieu);
     
    	timing->Load(fichier);
    }
    classe cours:
    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
    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
    #include "Cours.h"
    #include "Timing.h"
    #include "Professeur.h"
    #include "Groupe.h"
    #include "Local.h"
     
    Cours::Cours()
    {
    	Professeur = NULL;
    }
     
    Cours::~Cours()
    {
    	if(Professeur)
    		delete Professeur;
    }
     
    char *Cours::getProfesseur()const
    {
    	return Professeur;
    }
     
    void Cours::setProfesseur(const char *professeur)
    {
    	if(Professeur)
    		delete Professeur;
     
    	if(professeur)
    	{
    		Professeur = new char[strlen(professeur)+1];
    		strcpy(Professeur, professeur);
    	}
    	else
    		Professeur = NULL;
    }
    void Cours::setGroupe(const int g)
    {
    	groupe.insere(g);
    }
     
    Cours & Cours::operator=(const Cours &c)
    {
    	setProfesseur(c.getProfesseur());
    }
    bool Cours::operator==(const Cours &c)
    {
    	return getTiming() == c.getTiming();
    }
     
    bool Cours::operator>(const Cours &c)
    {
    	return getTiming() > c.getTiming();
    }
     
    bool Cours::operator<(const Cours &c)
    {
    	return getTiming() < c.getTiming();
    }
     
    ostream& operator<< (ostream& flux, const Cours &c)
    {
     
    	flux << "Code: "<< c.getCode() << endl;
    	flux << "Intitule: ";
    	if(!(c.getIntitule()))
    		flux << "Inconnu" << endl;
    	else
    		flux << c.getIntitule() << endl;
    	flux << "Lieu: ";
    	if(!(c.getLieu()) || strcmp(c.getLieu(), "")==0)
    		flux << "Inconnu" << endl;
    	else
    		flux << c.getLieu() << endl;
    	if(c.timing)
    		flux << c.getTiming();
    	flux << "Professeur: ";
    	if(c.getProfesseur())
    		flux << c.getProfesseur();
    	flux << endl << "Groupe: ";
    	c.groupe.Affiche();
     
    	return flux;
    }
    J'ai ensuite 3 autres classes (Professeur, Local et Groupe) qui héritent de planifiable.

    classe Professeur:
    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
    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    #include "Professeur.h"
     
    Professeur::Professeur()
    {
    	Nom = NULL;
    	Prenom = NULL;
    	strcpy(Identifiant, " ");
    	setType('h'); 
    }
     
    Professeur::Professeur(const char *N, const char *P)
    {
    	Nom = NULL;
    	Prenom = NULL;
    	setNom(N);
    	setPrenom(P);
    	strcpy(Identifiant, getIdentifiant());
    	setType('h');
    }
     
    Professeur::~Professeur()
    {
    	//cout << "destructeur professeur"<<endl;
    	if(Nom)
    		delete Nom;
    	if(Prenom)
    		delete Prenom;
    	Nom = NULL;
    	Prenom = NULL;
    }
     
    Professeur::Professeur(const Professeur &copie)
    {
    	Nom = NULL;
    	Prenom = NULL;
    	setNom(copie.getNom());
    	setPrenom(copie.getPrenom());
    }
     
    void Professeur::setNom(const char *N)
    {
    	if(Nom)
    		delete Nom;
    	Prenom = NULL;
    	if(N)
    	{
    		Nom = new char[strlen(N)+1];
    		strcpy(Nom, N);
    	}
    }
     
    void Professeur::setPrenom(const char *P)
    {
    	if(Prenom)
    		delete Prenom;
    	Prenom = NULL;
    	if(P)
    	{
    		Prenom = new char[strlen(P)+1];
    		strcpy(Prenom, P);
    	}
    }
     
    char *Professeur::getNom()const
    {
    	return Nom;
    }
     
    char *Professeur::getPrenom()const
    {
    	return Prenom;
    }
     
    const char *Professeur::getIdentifiant()
    {
    	sprintf(Identifiant, "%s %s", Nom, Prenom);
    	return Identifiant;
    }
     
     
    void Professeur::Affiche()
    {
    	if(Nom)
    		cout << Nom;
    	else
    		cout << "NULL";
    	cout << ", ";
    	if(Prenom)
    		cout << Prenom;
    	else
    		cout << "NULL";
    	cout << ", ";
    	cout << getIdentifiant() << endl;
    }
     
    ostream& operator<< (ostream& flux, const Professeur &P)
    {
    	if(P.getNom() && P.getPrenom())
    	{
    		flux << "Nom: " << P.getNom() << endl;
    		flux << "Prenom: " << P.getPrenom() << endl;
    	}
    	return flux;
     
    }
    istream& operator>> (istream& flux, Professeur &P)
    {
    	char nom[30], prenom[30];
     
    	do
    	{
    		cout << "Nom : ";
    		flux >> nom;
    	}while(strlen(nom) >= 30);
     
    	do
    	{
    		cout << "Prenom : ";
    		flux >> prenom;
    	}while(strlen(prenom) >= 30);
     
    	P.setNom(nom);
    	P.setPrenom(prenom);
    	return flux;
    }
     
    Professeur& Professeur::operator=(const Professeur& p)
    {
    	setNom(p.getNom());
    	setPrenom(p.getPrenom());
    	getIdentifiant();
    	return *this;
    }
     
    bool Professeur::operator==(const Professeur &e)
    {
    	if(strcmp(e.getNom(), getNom()) == 0)
    		return true;
     
    	return false;
    }
     
    bool Professeur::operator>(const Professeur &e)
    {
    	if(strcmp(getNom(), e.getNom()) > 0)
    		return true;
    	if(strcmp(getNom(), e.getNom()) == 0 && strcmp(getPrenom(), e.getPrenom()) > 0)
    		return true;
     
    	return false;
    }
     
    bool Professeur::operator<(const Professeur &e)
    {
    	if(strcmp(getNom(), e.getNom()) < 0)
    		return true;
    	if(strcmp(getNom(), e.getNom()) == 0 && strcmp(getPrenom(), e.getPrenom()) < 0)
    		return true;
     
    	return false;
    }
     
    void Professeur::Load(ifstream &fichier)
    {
    	char *nom = NULL, *prenom = NULL;
    	string NomPrenom;
     
    	getline(fichier, NomPrenom, ';');
    	nom = new char[NomPrenom.size()+1];
    	strcpy(nom, NomPrenom.c_str());
    	//NomPrenom.copy(nom, NomPrenom.size(), 0);
     
    	NomPrenom.erase(0, NomPrenom.size());
     
    	getline(fichier, NomPrenom);
    	prenom = new char [NomPrenom.size()+1];
    	strcpy(prenom, NomPrenom.c_str());
    	//NomPrenom.copy(prenom, NomPrenom.size(), 0);
     
    	setNom(nom);
    	setPrenom(prenom);
    }
    classe Groupe:
    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
    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
    #include "Groupe.h"
     
    Groupe::Groupe()
    {
    	Numero = 0;
    	strcpy(Identifiant, " ");
    	setType('m');
    }
     
    Groupe::Groupe(int N)
    {
    	setNumero(N);
    	strcpy(Identifiant, getIdentifiant());
    	setType('m');
    }
     
    Groupe::~Groupe()
    {
     
    }
     
    Groupe::Groupe(const Groupe &copie)
    {
    	setNumero(copie.getNumero());
    }
     
    void Groupe::setNumero(const int N)
    {
    	Numero = N;
    }
     
    int Groupe::getNumero()const
    {
    	return Numero;
    }
     
    const char *Groupe::getIdentifiant()
    {
    	sprintf(Identifiant, "G%d", Numero);
    	return Identifiant;
    }
     
    void Groupe::Affiche()
    {
    	cout << "Numero : " << Numero << endl;
    }
     
    Groupe& Groupe::operator=(const Groupe& g)
    {
    	setNumero(g.getNumero());
     
    	return *this;
    }
     
    bool Groupe::operator==(const Groupe &g)
    {
    	if(g.getNumero() == getNumero())
    		return true;
     
    	return false;
    }
     
    bool Groupe::operator>(const Groupe &g)
    {
    	if(g.getNumero() > getNumero())
    		return true;
     
    	return false;
    }
     
    bool Groupe::operator<(const Groupe &g)
    {
    	if(g.getNumero() < getNumero())
    		return true;
     
    	return false;
    }
     
    ostream& operator<< (ostream& flux, const Groupe &G)
    {
    	flux << "Groupe: " << G.getNumero()<< endl;
     
    	return flux;
    }
     
    istream& operator>> (istream& flux, Groupe &G)
    {	
    	int groupe;
     
    	cout << "Groupe : ";
    	flux >> groupe;
     
    	G.setNumero(groupe);
    }
     
    void Groupe::Load(ifstream &fichier)
    {
     
    	int grp;
    	string g;
    	string temp;
     
    	if(getline(fichier, g))
    	{
    		temp = g.substr(g.find_last_of(';')+1);
    		grp = atoi(temp.c_str());
     
    		setNumero(grp);
    	}
    }
    classe local:
    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
    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    #include "Local.h"
    #include <string>
     
    Local::Local()
    {
    	Nom = NULL;
    	NbPlaces = 0;
    	setType('m');
    	strcpy(Identifiant, getIdentifiant());
    }
     
    Local::Local(const char *N, const int Nb)
    {
    	Nom = NULL;
    	setNom(N);
    	setNbPlaces(Nb);
    	setType('m');
    	strcpy(Identifiant, getIdentifiant());
    }
     
    Local::~Local()
    {
    	if(Nom)
    		delete Nom;
    	Nom = NULL;
    }
     
    Local::Local(const Local &copie)
    {
    	setNom(copie.getNom());
    	setNbPlaces(copie.getNbPlaces());
    }
     
    void Local::setNom(const char *N)
    {
    	if(Nom)
    		delete Nom;
    	if(N)
    	{
    		Nom = new char[strlen(N)+1];
    		strcpy(Nom, N);
    	}
    	else
    		Nom = NULL;
    }
     
    void Local::setNbPlaces(const int Nb)
    {
    	NbPlaces = Nb;
    }
     
    char *Local::getNom()const
    {
    	return Nom;
    }
     
    int Local::getNbPlaces()const
    {
    	return NbPlaces;
    }
     
    const char *Local::getIdentifiant()
    {
    	sprintf(Identifiant, "%s(%d)", Nom, NbPlaces);
    	return Identifiant;
    }
     
    void Local::Affiche()
    {
    	if(Nom)
    		cout << "Nom: " << Nom << endl;
    	else
    		cout << "Nom: NULL" << endl;
     
    	cout << "NbPlaces: " << NbPlaces << endl;
    }
     
    Local& Local::operator=(const Local& l)
    {
    	setNom(l.getNom());
    	setNbPlaces(l.getNbPlaces());
    	return *this;
    }
     
    bool Local::operator==(const Local &l)
    {
    	if(l.getNbPlaces() == getNbPlaces())
    		return true;
     
    	return false;
    }
     
    bool Local::operator>(const Local &l)
    {
    	if(getNbPlaces() > l.getNbPlaces())
    		return true;
     
    	return false;
    }
     
    bool Local::operator<(const Local &l)
    {
    	if(getNbPlaces() < l.getNbPlaces())
    		return true;
     
    	return false;
    }
     
    ostream& operator<< (ostream& flux, const Local& L)
    {
    	flux << "Nom : " << L.getNom() << endl;
    	flux << "NbPlaces : " << L.getNbPlaces() << endl;
     
    	return flux;
    }
     
    istream& operator>> (istream& flux, Local& L)
    {
    	char nom[30];
    	int place;
     
    	do
    	{
    		cout << "Nom: ";
    		flux >> nom;
    	}while(strlen(nom) >=30);
     
    	cout << "NbPlaces : ";	
    	flux >> place;
     
    	L.setNom(nom);
    	L.setNbPlaces(place);
     
    	return flux;
    }
     
    void Local::Load(ifstream &fichier)
    {
    	int nbi;
    	string nb;
    	char *loc = new char[20];
    	string loca;
    	getline(fichier, loca, ';');
    	strcpy(loc, loca.c_str());
    	setNom(loc);
    	delete loc;
    	getline(fichier, nb);
    	nbi = atoi(nb.c_str());
    	setNbPlaces(nbi);
    }
    et la classe planifiable.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
    23
    24
    25
    26
    27
    #ifndef PLANIFIABLE_H
    #define PLANIFIABLE_H
    #include <iostream>
    using namespace std;
    #include "Timing.h"
    #include "ListeTriee.h"
    #include "SmartPointer.h"
     
    class Planifiable
    {
    	protected:
    		char Type;
    		ListeTriee< SmartPointer<Cours> > horaire;
    	public:
    		Planifiable();
    		Planifiable(Planifiable &);
    		virtual ~Planifiable();
     
    		void setType(const char);
    		const char getType();
     
    		virtual const char *getIdentifiant() = 0;
    		bool estDisponible(const Timing &t);
     
    		void Affiche();
    };
    #endif
    planifiable.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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #include "Planifiable.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    using namespace std;
     
    Planifiable::Planifiable()
    {
     
    }
     
    Planifiable::Planifiable(Planifiable &copie)
    {
    	setType(copie.getType());
    }
     
    Planifiable::~Planifiable()
    {
     
    }
     
    void Planifiable::setType(const char T)
    {
    	Type = T;
    }
     
    const char Planifiable::getType()
    {
    	return Type;
    }
     
    void Planifiable::Affiche()
    {
    	cout << "Type: " << getType() << endl;
    }

    Et pour finir une classe SmartPointer:
    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
    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
    #include "SmartPointer.h"
     
    template<class T>
    SmartPointer<T>::SmartPointer()
    {
    	val = NULL;
    }
     
    template<class T>
    SmartPointer<T>::SmartPointer(T*v)
    {
    	val = v;
    }
     
    template<class T>
    SmartPointer<T>::~SmartPointer()
    {
    	val = NULL;
    }
     
    template<class T>
    SmartPointer<T>::SmartPointer(const SmartPointer &s)
    {
    	val = s.val;
    }
     
    template<class T>
    void SmartPointer<T>::Delete()
    {
    	delete val;
    }
     
    template<class T>
    T* SmartPointer<T>::getValeur()
    {
    	return val;
    }
    template<class T>
    T SmartPointer<T>::operator*(void)
    {
    	return *val;
    }
    template<class T>
    bool SmartPointer<T>::operator==(const SmartPointer &s)
    {
    	return operator==(s);
    }
    template<class T>
    bool SmartPointer<T>::operator>(const SmartPointer &s)
    {
    	return operator>(s);
    }
    template<class T>
    bool SmartPointer<T>::operator<(const SmartPointer &s)
    {
    	return operator<(s);
    }
     
    template class SmartPointer<Cours>;

    à l'aide de la classe SmartPointer, je dois créer une liste triée de smartpointer<cours>.
    J'ai juste un soucis, lors de la compilation j'ai une erreur:

    louis@ubuntu:~/Documents/C++2015$ make
    Creation de Planifiable
    Creation de App
    Planifiable.o: dans la fonction « ListeTriee<SmartPointer<Cours> >::ListeTriee() »:
    Planifiable.cpp.text._ZN10ListeTrieeI12SmartPointerI5CoursEEC2Ev[_ZN10ListeTrieeI12SmartPointerI5CoursEEC5Ev]+0x14): référence indéfinie vers « ListeBase<SmartPointer<Cours> >::ListeBase() »
    Planifiable.o: dans la fonction « ListeTriee<SmartPointer<Cours> >::~ListeTriee() »:
    Planifiable.cpp.text._ZN10ListeTrieeI12SmartPointerI5CoursEED2Ev[_ZN10ListeTrieeI12SmartPointerI5CoursEED5Ev]+0x1f): référence indéfinie vers « ListeBase<SmartPointer<Cours> >::~ListeBase() »
    collect2: error: ld returned 1 exit status
    make: *** [App] Erreur 1
    louis@ubuntu:~/Documents/C++2015$

    J'ai beau chercher partout sur internet, je ne trouve rien m'aidant à régler ce problème..

    Votre aide est donc la bienvenue !


    Je vous mets en pièce jointe mon dossier complet si jamais les extraits de code que j'ai mis ci contre ne suffiraient pas.
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    J'ai du mal à voir en quoi elle est "smart", ta classe de pointeur...

    Mais ton erreur, c'est que tu as déclaré, mais pas implémenté, le constructeur par défaut et le destructeur de ta classe ListeBase<>.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Expert éminent
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 565
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 565
    Points : 7 648
    Points
    7 648
    Par défaut
    Bonjour,

    Les erreurs sont : Les constructeurs et destructeurs de ListeBase<> n'ont pas été trouvés au moment de l'édition des liens.
    Dans ton archive, il y a bien ces fonctions mais elles sont dans un fichier cpp alors que ce sont des template.
    Si les template sont dans un cpp, le compilateur quand il les voit ne peut pas deviner qu'il faut les créer pour le cas ListeTriee<SmartPointer<Cours>>.
    Alors, ou bien on met tous les template dans le fichier listebase.h (le mieux), ou bien dans le fichier cpp on doit forcer une instanciation du template dans tous les cas ou va l'utiliser en faisant : template<> ListeTriee<SmartPointer<Cours> >;

Discussions similaires

  1. Recherche d'un élément dans une liste triée (vitesse)
    Par Rodrigue dans le forum Algorithmes et structures de données
    Réponses: 9
    Dernier message: 18/05/2006, 09h23
  2. pointeur intelligent??
    Par yashiro dans le forum C++
    Réponses: 3
    Dernier message: 04/04/2006, 08h08
  3. [Débutant]Liste Chaînés et pointeurs
    Par mikedavem dans le forum C
    Réponses: 16
    Dernier message: 24/03/2006, 16h18
  4. Pointeur intelligent boost : return NULL ->comment faire?
    Par choinul dans le forum Bibliothèques
    Réponses: 7
    Dernier message: 21/12/2005, 16h24
  5. [LG]Listes chainées avec pointeur
    Par PaowZ dans le forum Langage
    Réponses: 2
    Dernier message: 17/02/2004, 19h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo