Bonjour,
J'aimerais définir un tableau d'entier vector<int> dans une classe mais j'ai un soucis avec mon code, je vous avouerai que c'est un peu déroutant pour moi contrairement à l'utilisation de variable comme attribut c'est plus simple. Alors voici le code que j'ai élaboré:
classe.h:
classe.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 #ifndef FILM_H #define FILM_H #include "video.h" #include <iostream> #include <vector> using namespace std; class film : public Video { public: //Constructeur film(string const& un_nom, size_t une_date, string nom_fichier, double une_duree, int un_chapitre); //Accesseurs int getChapitre() const; vector<int> getTableau() const; //Modifieurs void setTableau(vector<int> tab); //Methode d'affichage virtual void afficher(ostream&) const; //Destructeur virtual ~film(){} protected: int chapitre; vector<int> tableau; }; #endif // FILM_H
Alors je sais pas comment definir la taille du tableau, ni même comment l'initialiser en ne passant pas par le constructeur, si quelqu'un a une idée?
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 #include "film.h" film::film(string const& un_nom, size_t une_date, string nom_fichier, double une_duree, int un_chapitre) : Video(un_nom, une_date, nom_fichier, une_duree), chapitre(un_chapitre) { cout << "Construction de la platforme de films " << endl; } vector<int> film::getTableau() const { return tableau; } int film::getChapitre() const { return chapitre; } void film::setTableau(vector<int> tab) { tableau = tab; } void film::afficher(ostream& sortie) const { Video::afficher(sortie); for(int i(0); i< getChapitre(); ++i) { sortie << "Chapitre " << i+1 << " :" << endl << tableau[i] << endl; } }
Partager