Bonjour,
J'ai une classe mère "Produit" avec des classes filles comme "Ordinateur". Et j'utilise la STL multimap pour créer ma liste de produit.
Le problème c'est qu'il ne veut pas utiliser la fonction "afficher_fiche_produit()" de la classe Ordinateur (car je veux afficher des spécificités). Comment faire pour que je puisse faire une multimap de différents produits? Merci de votre aide
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 class Produit { public: Produit();//Constructeur Produit(std::string tmp_marque, std::string tmp_nom, std::string tmp_type, double tmp_prix); Produit(const Produit &exemple);//Constructeur par recopie ~Produit(); //Destructeur //Mutateurs void SetMarque(std::string tmp_marque); void SetNom(std::string tmp_nom); void SetCode(std::string tmp_code); void SetType(std::string tmp_categorie); void SetPrix(double tmp_prix); //Accesseurs std::string GetMarque(); std::string GetNom(); std::string GetCode(); std::string GetType(); double GetPrix(); virtual void afficher_fiche_produit() { std::cout << "Code barre: " << GetCode() << std::endl; std::cout << "Marque: " << GetMarque() << std::endl; std::cout << "Nom: " << GetNom() << std::endl; std::cout << "Prix: " << GetPrix() << std::endl; } protected: std::string marque; //Marque du produit std::string nom; //Nom du produit std::string code_barre;//Code barre du produit std::string type; //Type de produit double prix; //Prix du produit }; class Ordinateur: public Produit { public: //Constructeur et destructeur Ordinateur(); Ordinateur(std::string tmp_marque, std::string tmp_nom, std::string tmp_type, std:: string tmp_cate, double tmp_prix); Ordinateur(const Ordinateur &exemple); ~Ordinateur(); //Mutateur et Accesseur void SetCategorie(std::string tmp_cate); std::string GetCategorie(); void afficher_fiche_produit() { Produit::afficher_fiche_produit(); cout << "Type: Ordinateur" << endl; cout << "Categorie: " << this->categorie << endl; } protected: std::string categorie; } typedef std::multimap<std::string, class Produit> Liste_produit; class Stock { public: Stock(void); ~Stock(void); void ajouter_produit_liste(std::string marque, std::string nom, Produit exemple); void afficher_data_produit() { for(multimap<string, Produit>::iterator it = liste_produit_magasin.begin(); it != liste_produit_magasin.end(); ++it) { if(it->second.GetType() == "P") { it->second->afficher_fiche_produit(); } } private: Liste_produit liste_produit_magasin; };
Partager