Bonjour, je développe en débutant un petit programme perso.
j'utilise CLion sur MacOS
Comme je commence à avoir pas mal de tableaux, j'ai trouvé plus propre de les placer dans un autre fichier.
Mais ma demande dd'appel de fonctionne plus
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part int EQUmax = PerEQU[per]+CEQU[c]+TEQU[t]+PEQU[p];
je veux faire la somme de PerEQU ; CEQU ; TEQU et PEQU (PerEQU ; CEQU ; TEQU et PEQU étant des tableau à 21 entrés) en allant chercher l'entré défini par per ; c ; t et p qui sont défini plus loin.
Mes tableau sont écrit comme cela
Code C++ : 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 int const CEQUILIBRE(21); int CEQU[CEQUILIBRE]; CEQU[0] = 0; CEQU[1] = 0; CEQU[2] = 0; CEQU[3] = 0; CEQU[4] = 0; CEQU[5] = 2; CEQU[6] = 4; CEQU[7] = 8; CEQU[8] = 12; CEQU[9] = 16; CEQU[10] = 20; CEQU[11] = 22; CEQU[12] = 24; CEQU[13] = 26; CEQU[14] = 28; CEQU[15] = 30; CEQU[16] = 32; CEQU[17] = 34; CEQU[18] = 36; CEQU[19] = 38; CEQU[20] = 40;
J'ai donc un ficher main cpp avec
Code C++ : 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 #include "tableau.h" un fichier tableau.h #ifndef TABLEAUX_H #define TABLEAUX_H #include <vector> #include <string> // Déclaration des tableaux avec 'extern' (sans fixer la taille ni les valeurs) extern int const PerEQUILIBRE(21); extern int const CEQUILIBRE(21); extern int const TEQUILIBRE(21); extern int const PEQUILIBRE(21);
et un fichier tableau.cpp
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 #include "tableau.h" //Tableau des compétences // EQUILIBRE (EQU) carac utilisées Per C T P // Tabl pour C d'EQU CEQU extern int CEQU[CEQUILIBRE]; CEQU[0] = 0; CEQU[1] = 0; CEQU[2] = 0; CEQU[3] = 0; CEQU[4] = 0; #endif
Dans main.ccp
j'ai inclu ça :
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5int PerEQU[PerEQUIKIBRE]; int CEQU[CEQUILIBRE]; int TEQU[TEQUILIBRE]; int PEQU[PEQUILIBRE];
si non il compile pas avec une erreur de "error: subscripted value is not an array, pointer, or vector"
Quand je place simplement tout dans main.ccp ça fonctionne bien, mais ça va rapidement être le fouillis
avec ce que j'ai écrit il me sort des valeurs type x7ff7bb75ff80. et le résultat de la somme est -1149861830 au lieu d'un chiffre entre 0 et 100
Qu'est ce que je fait de mal ?






Répondre avec citation
Partager