Bonjour,
Je suis toujours sur le projet pour lequel j'avais demandé de l'aide dans ce thread: http://www.developpez.net/forums/sho...d.php?t=154525
Après avoir un peu avancé, je suis face à un nouveau problème.
A la compilation j'obtiens cette erreur:
Celle-ci concerne le code suivant:c:\Documents and Settings\Fabrice\Bureau\Project\C++\GATest\GADiploid.h(30) : error C2504: 'GABinaryString' : classe de base non définie
Je travaille sur une bibliothèque que je cherche à étendre. J'ai repris l'un des fichiers de cette bibliothèque et l'ai modifié pour obtenir le code qui précède.
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 #ifndef _ga_binstr_h_ #define _ga_binstr_h_ #include <string.h> #include <ga/gatypes.h> #include <ga/garandom.h> #include <ga/GABinStr.h> #include <ga/GAGenome.h> #define GA_BINSTR_CHUNKSIZE 32 // size of the chunks of bits we allocate class GADiploid : public GABinaryString, public GAGenome { public: GADiploid(unsigned int s); GADiploid::GADiploid(const GADiploid& orig); virtual ~GADiploid(); void copy(const GADiploid&); int resize(unsigned int); // pass desired size, in bits int size() const {return sz;} short bit(unsigned int a, unsigned int c) const { if (c = '1') return(Chrom_1->bit(a)); else return(Chrom_2->bit(a)); } short bit(unsigned int a, short val, unsigned int c) { // set/unset the bit if (c = '1') return(Chrom_1->bit(a, val)); else return(Chrom_2->bit(a, val)); } int equal(const GADiploid & b, unsigned int r, unsigned int x, unsigned int l, unsigned int c) const { if (c = '1') return(Chrom_1->equal(b.Chrom_1[0], r, x, l)); else return(Chrom_2->equal(b.Chrom_2[0], r, x, l)); } void copy(const GADiploid & orig, unsigned int r, unsigned int x, unsigned int l, unsigned int c) { if (c = '1') Chrom_1->copy(orig.Chrom_1[0], r, x, l); else Chrom_2->copy(orig.Chrom_2[0], r, x, l); } void move(unsigned int r, unsigned int x, unsigned int l, unsigned int c) { if (c = '1') Chrom_1->move(r, x, l); else Chrom_2->move(r, x, l); } void set(unsigned int a, unsigned int l, unsigned int c) { if (c = '1') Chrom_1->set(a, l); else Chrom_2->set(a, l); } void unset(unsigned int a, unsigned int l, unsigned int c) { if (c = '1') Chrom_1->unset(a, l); else Chrom_2->unset(a, l); } void randomize(unsigned int a, unsigned int l, unsigned int c) { if (c = '1') Chrom_1->randomize(a, l); else Chrom_2->randomize(a, l); } void randomize(unsigned int c) { if (c = '1') Chrom_1->randomize(); else Chrom_2->randomize(); } GABinaryString *Chrom_1; GABinaryString *Chrom_2; //GABinaryString Mask; protected: unsigned int sz; // size of chrom unsigned int SZ; // size of the memory allocated unsigned int csz; // size of chunks we allocate }; #endif
Pour résoudre l'erreur j'ai essayé de commenter le ifndef:
L'erreur disparaît, mais j'obtiens maintenant cette erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 //#ifndef _ga_binstr_h_ //#define _ga_binstr_h_ [...] //#endif
Celle-ci concernant ce fichier:c:\Documents and Settings\Fabrice\Bureau\Project\C++\GATest\GADiploid.cpp(35) : error C2512: 'GABinaryString' : aucun constructeur par défaut approprié disponible
Le compilateur me réclame un constructeur par défaut alors que celui-ci semble bien défini dans le fichier suivant (fichier que j'ai récupéré dans la bibliothèque, sans modification):
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 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ga/gaerror.h> #include <GADiploid.h> GADiploid::GADiploid(unsigned int s): GABinaryString(s) { Chrom_1 = new GABinaryString(s); Chrom_2 = new GABinaryString(s); //resize(s); //Mask = new GABinaryString(s); } GADiploid::GADiploid(const GADiploid& orig) { sz=0; SZ=0; data=(GABit *)0; copy(orig); } void GADiploid::copy(const GADiploid& orig) { if(&orig == this) return; Chrom_1->copy(orig.Chrom_1[0]); Chrom_2->copy(orig.Chrom_2[0]); } int GADiploid::resize(unsigned int x) { Chrom_1->resize(x); Chrom_2->resize(x); return(sz = x); }
Deux questions:
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 #ifndef _ga_binstr_h_ #define _ga_binstr_h_ #include <string.h> #include <ga/gatypes.h> #include <ga/garandom.h> #define GA_BINSTR_CHUNKSIZE 32 // size of the chunks of bits we allocate class GABinaryString { public: GABinaryString(unsigned int s){ csz=GA_BINSTR_CHUNKSIZE; sz=0; SZ=0; data=(GABit *)0; resize(s); } GABinaryString(const GABinaryString& orig){ sz=0; SZ=0; data=(GABit *)0; copy(orig); } virtual ~GABinaryString(){delete [] data;} void copy(const GABinaryString&); int resize(unsigned int); // pass desired size, in bits int size() const {return sz;} short bit(unsigned int a) const { return(data[a]); } short bit(unsigned int a, short val) { // set/unset the bit return(data[a] = (val ? 1 : 0)); } int equal(const GABinaryString & b, unsigned int r, unsigned int x, unsigned int l) const { return(memcmp(&(data[r]),&(b.data[x]),l*sizeof(GABit))?0:1); } void copy(const GABinaryString & orig, unsigned int r, unsigned int x, unsigned int l){ memcpy(&(data[r]), &(orig.data[x]), l*sizeof(GABit)); } void move(unsigned int r, unsigned int x, unsigned int l){ memmove(&(data[r]), &(data[x]), l*sizeof(GABit)); } void set(unsigned int a, unsigned int l){ memset(&(data[a]), 1, l*sizeof(GABit)); } void unset(unsigned int a, unsigned int l){ memset(&(data[a]), 0, l*sizeof(GABit)); } void randomize(unsigned int a, unsigned int l){ for(unsigned int i=0; i<l; i++) data[i+a] = (GABit)GARandomBit(); } void randomize(){ for(unsigned int i=0; i<sz; i++) data[i] = (GABit)GARandomBit(); } protected: unsigned int sz; // size of chrom unsigned int SZ; // size of the memory allocated unsigned int csz; // size of chunks we allocate GABit *data; // the data themselves }; #endif
-A quoi sert le code #ifndefine... #define... #endif que j'ai mis en commentaire?
-Pour quoi le compilateur me réclame-t-il un constructeur par défaut?
Merci d'avance pour vos réponses.
Partager