forward declaration of ‘struct/invalid use of incomplete type ‘struct

HI
i am coding some pointer manipulation :liked list of linked list
but am getting forward declaration and invalid use of incomplete type ‘struct
i'v seen http://www.cplusplus.com/forum/articles/10627/#msg49682 but i still not get it with this code
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
        /*
     * neuMot.h
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
     
    #ifndef NEUCARTE_H_
    #define NEUCARTE_H_
    using namespace std;
    #include <stdlib.h>
    #include"neuCarte.h"
     
     
     
     
    class neuMot{
        public:
            neuCarte * data;
        neuMot * next;
        neuMot * previous;
     
        public:
        neuMot(neuCarte* x);
        neuMot(neuCarte* x, neuMot * n,neuMot *p);
    };
    #endif /* NEUCARTE_H_ */
     
    /*
     * neuMot.cpp
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
     
    #include "neuMot.h"
     
     
    neuMot::neuMot(neuCarte* x){
                    data = x;
                    next = NULL;
                    previous = NULL;
                    }
     
    neuMot::neuMot(neuCarte* x, neuMot * n,neuMot *p){
                    data = x;
                    next = n;
                    previous = p;
     
                    }
     
     
    /*
     * neuCarte.h
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
     
    #ifndef NEUCARTE_H_
    #define NEUCARTE_H_
    #include <stdlib.h>
     
    using namespace std;
     
     
    class neuCarte{
        public:
        char data;
        neuCarte * next;
        public:
        neuCarte(char x);
        neuCarte(char x, neuCarte * y);
    };
    #endif /* NEUCARTE_H_ */
     
    /*
     * neuCarte.cpp
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
    #include "neuCarte.h"
     
     
     
    neuCarte::neuCarte(char x){
                    data = x;
                    next = NULL;
                    }
     
    neuCarte::neuCarte(char x, neuCarte * y){
                    data = x;
                    next = y;
                    }
     
    /*
     * Centre.h
     *
     *  Created on: 29 avr. 2013
     *      Author: bravvve
     */
     
    #ifndef CENTRE_H_
    #define CENTRE_H_
     
     
     
    #include <string>
     
    using namespace std ;
    #include "neuCarte.h"
    //#include "neuMot.h"
     
    //class neuMot;
    class neuCarte;
     
    //
     
    class Centre {
    public:
            Centre(neuCarte &nc);
            void ajoutNeu();
            void CreeCentre();
            string VisualiserCentre();
     
            neuMot* tete;
            neuMot* queu;
            neuCarte& donne;
            int complet;
     
    };
     
    #endif /* CENTRE_H_ */
     
    /*
     * Centre.cpp
     *
     *  Created on: 29 avr. 2013
     *      Author: bravvve
     */
     
    #include "Centre.h"
    #include "neuCarte.h"
     
    class neuMot;     //forward declaration of ‘struct neuMot’ERROR
     
    Centre::Centre(neuCarte &nc) :
            donne(nc) {
            // TODO Auto-generated constructor stub
            tete = new neuMot(&donne);   //invalid use of incomplete type ‘struct neuMot’
            queu = tete;                 //‘queu’ was not declared in this scope
            complet = 0;
            //donne=nc;
    }
     
    void Centre::ajoutNeu() {
            neuMot* p = new neuMot(&donne);     //invalid use of incomplete type ‘struct neuMot’ ERROR
            queu->next = p;                     //‘queu’ was not declared in this scope ERROR
            p->previous = queu;                 //invalid use of incomplete type ‘struct neuMot’ERROR
            queu = p;
            p = NULL;
    }
     
    void Centre::CreeCentre() {
            for (int i = 0; i < 8; i++) {
                    ajoutNeu();
            }
    }
    string Centre::VisualiserCentre() {
            neuMot* p = new neuMot(NULL);     //invalid use of incomplete type ‘struct neuMot’ ERROR
            neuCarte* q = new neuCarte('A');
            string s = "";
            p = tete;                         //‘tete’ was not declared in this scope ERROR
            while (p = p->next) {             //invalid use of incomplete type ‘struct neuMot’ ERROR
                    q = p->data;              //invalid use of incomplete type ‘struct neuMot’ ERROR
                    s = s + q->data;
            }
            return s;
    }
     
     
    /*
     * Carte.h
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
     
    #ifndef CARTE_H_
    #define CARTE_H_
     
    #include"neuCarte.h"
     
    class Centre;
    class Carte{
    public:
            Carte();
            void ajoutNeu(char x);
            void CreeCarte();
            void VisualiserCarte();
     
            neuCarte* tete;  //expected ‘;’ before ‘*’ token ERROR
            neuCarte* queu;  //expected ‘;’ before ‘*’ token ERROR
     
            int complet;
    };
    #endif /* CARTE_H_ */
     
    /*
     * Carte.cpp
     *
     *  Created on: 30 avr. 2013
     *      Author: bravvve
     */
     
    #include"Carte.h"
     
     
     
    #include <iostream>
     
    Carte::Carte(){
    tete = new neuCarte('0');
    queu=tete;
    complet=0;
     
    }
     
    void Carte::ajoutNeu(char x){
            neuCarte* q= new neuCarte(x);
            queu->next=q;
            queu=q;
            q=NULL;
    }
     void Carte::CreeCarte(){
     
    for(int i=49;i<123;i++){
    if (i==58)i=65;if(i==91)i=97;
            ajoutNeu((char)i);
    //      cout << (char)i << endl;
     
     }
    complet=1;
     }
    void Carte::VisualiserCarte(){
            neuCarte* q=tete;
            cout << q->data << endl;
            while(q=q->next)
                    cout << q->data << endl;
     
    }


how can i fix that
You can use forward declaration only when the compiler does not need to know what the type/class really is.

For example it's correctly used in Centre.h. Since you're only passing pointers, the internal details of the pointed to classes are not needed.

But in Centre.cpp you're creating new neuMots using the constructor. Therefore these details are needed, and you have to provide the full definition of the neuMot class.
Last edited on
Topic archived. No new replies allowed.