Can anyone help me fix this error?

Qualified - id in declaration before '(' token

void PartsCatalog::Insert(Part * newPart)
^

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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
  #include <iostream>

typedef unsigned long ULONG;
typedef unsigned short USHORT;
// Abstract base of parts

class Part
{
    public:
    Part():itsPartNumber(1){}
    Part(ULONG PartNumber):itsPartNumber(PartNumber){}
    virtual ~Part(){};
    ULONG GetPartNumber() const { return itsPartNumber; }
    virtual void Display() const =0; // must be overidden
private:
    ULONG itsPartNumber;
};

// implementation of pure virtual function so that
// derived classes can chain up
void Part::Display() const
{
    std::cout<<"\nPart Number: " << itsPartNumber << std::endl;
}

// ******* Car Part ********
class CarPart : public Part
{
public:
    CarPart():itsModelYear(94){}
    CarPart(USHORT year, ULONG partNumber);
    virtual void Display() const { Part::Display(); std::cout <<"Model Year: " << itsModelYear << std::endl; }
    
private:
    USHORT itsModelYear;
};

CarPart::CarPart(USHORT year, ULONG partNumber):
itsModelYear(year),
Part(partNumber)
{}

// ********* Airplane Part *********
class AirPlanePart : public Part
{
public:
    AirPlanePart():itsEngineNumber(1){};
    AirPlanePart(USHORT EngineNumber, ULONG PartNumber);
    virtual void Display() const { Part::Display(); std::cout <<"Engine No.."<< itsEngineNumber<< std::endl;}
    private:
    USHORT itsEngineNumber;
};

AirPlanePart::AirPlanePart(USHORT EngineNumber, ULONG PartNumber):
itsEngineNumber(EngineNumber),
Part(PartNumber)
{}

// ******** Part Node *******

class PartNode
{
public:
    friend class PartsList;
    PartNode(Part*);
    ~PartNode();
    void SetNext(PartNode * node) { itsNext = node; }
    PartNode * GetNext() const;
    Part * GetPart() const;
private:
    Part * itsPart;
    PartNode * itsNext;
};
// PartNode Implementations...

PartNode::PartNode(Part* pPart):
itsPart(pPart),
itsNext(0)
{}
    
PartNode::~PartNode()
{    
    delete itsPart;
    itsPart = 0;
    delete itsNext;
    itsNext = 0;
}

//Returns NULL if no next PartNode
PartNode * PartNode::GetNext()const
{
    return itsNext;
}

Part * PartNode::GetPart()const
{
    if (itsPart)
        return itsPart;
        else
            return NULL; // error
}

// ******** Parts List **********

class PartsList
{
public:
    PartsList();
    ~PartsList();
    // needs copy constructor and operator equals!
    void Iterate(void (Part::*f)()const)const;
    Part* Find(ULONG & position, ULONG PartNumber) const;
    Part* GetFirst()const;
    void  Insert(Part *);
    Part* operator[](ULONG)const;
    ULONG GetCount() const { return itsCount;}
    static PartsList& GetGlobalPartsList() { return GlobalPartsList;}  
private:
PartNode * pHead;
ULONG itsCount;
static PartsList GlobalPartsList;  
};

PartsList PartsList::GlobalPartsList;

// Implementations for lists....

PartsList::PartsList():
pHead(0),
itsCount(0)
{}

PartsList::~PartsList()
{
    delete pHead;
}

Part* PartsList::GetFirst() const
{
    if(pHead)
        return pHead->itsPart;
        else
            return NULL;
}

Part * PartsList::operator[](ULONG offset) const
{
    PartNode* pNode = pHead;
    
    if(!pHead)
        return NULL; // error catch here
        
        if(offset > itsCount)
            return NULL; // error
             for(ULONG i = 0; i<offset; i++)
                 pNode = pNode->itsNext;
                 
                 return pNode->itsPart;
}

Part* PartsList::Find(ULONG & position, ULONG PartNumber)const
{
    PartNode * pNode = 0;
    for(pNode = pHead, position = 0;
    pNode!=NULL;
    pNode = pNode->itsNext, position++)
    {
        if (pNode->itsPart->GetPartNumber() == PartNumber)
            break;
    }
    
if(pNode == NULL)
    return NULL;
    else
        return pNode-> itsPart;
}

void PartsList::Iterate(void (Part::*func)()const) const
{
    if (!pHead)
        return;
        PartNode* pNode = pHead;
        do
        (pNode->itsPart->*func)();
        while (pNode = pNode->itsNext);
}

void PartsList::Insert(Part* pPart)
{
    PartNode * pNode = new PartNode(pPart);
    PartNode * pCurrent = pHead;
    PartNode * pNext = 0;
    
    ULONG New = pPart->GetPartNumber();
    ULONG Next = 0;
    itsCount++;
    
    if(!pHead)
    {
        pHead = pNode;
        return;
    }
    
// If this one is smaller than head
// this one is the new head

if (pHead->itsPart->GetPartNumber() > New)
{
    pNode->itsNext = pHead;
    pHead = pNode;
    return;
}

for (;;)
{
    // if there is no next, append this new one
    if(!pCurrent->itsNext)
    {
        pCurrent->itsNext = pNode;
        return;
    }
    
// if this goes after this one and before the next
// then insert it here, otherwise get the next
pNext = pCurrent->itsNext;
Next = pNext->itsPart->GetPartNumber();
if(Next > New)
{
    pCurrent->itsNext = pNode;
    pNode->itsNext = pNext;
    return;
}
pCurrent = pNext;
}

class PartsCatalog : private PartsList
{
public:
    void Insert(Part *);
    ULONG Exists(ULONG PartNumber);
    Part * Get(int PartNumber);
    operator+(const PartsCatalog &);
    void ShowAll() { Iterate(&Part::Display);}
    private:
};

void PartsCatalog::Insert(Part * newPart)
{
    ULONG partNumber = newPart->GetPartNumber();
    ULONG offset;
    
    if (!Find(offset, partNumber))
        PartsList::Insert(newPart);
        else
        {
            std::cout << partNumber << " was the ";
            switch(offset)
            {
                case 0: std::cout <<"first "; break;
                case 1: std::cout <<"second "; break;
                case 2: std::cout <<"third " ; break;
                default: std::cout << offset+ << "th ";
            }
            std::cout<<"entry. Rejected!\n";
        }
}

ULONG PartsCatalog::Exists(ULONG PartNumber)
{
    ULONG offset;
    Find(offset,PartNumber);
    return offset;
}

Part * PartsCatalog::Get(int PartNumber)
{
    ULONG offset;
    return (Find(offset, PartNumber));
}

int main()
{
    PartsCatalog pc;
    Part * pPart = 0;
    ULONG PartNumber;
    USHORT value;
    ULONG choice;
    
    while(1)
    {
        std::cout<<"(0)Quit (1)Car (2)Plane: ";
        std::cin >> choice;
        if(!choice)
            break;
            
            std::cout<<"New Part Number?: ";
            std::cin >> PartNumber;
            
            if(choice == 1)
            {
                std::cout <<"Model Year?: ";
                std::cout >> value;
                pPart = new CarPart(value,PartNumber);
            }
            else
            {
                std::cout<<"Engine Number?: ";
                std::cin>> value;
                pPart = new AirPlane(value,PartNumber);
            }
            pc.Insert(pPart);
    }
    pc.ShowAll()
}
That is not the first error:
242:35: error: ISO C++ forbids declaration of 'operator+' with no type [-fpermissive]
247:26: error: qualified-id in declaration before '(' token 

Fix the first error first.
Your function void PartsList::Insert(Part* pPart) never ends.

You can't see it because around line 206 you gave up on sensible indentation.
Last edited on
This is a duplicate of http://www.cplusplus.com/forum/beginner/243219/ . You were given plenty of helpful advice in that thread, that would have helped you find and fix the problem, if you'd paid any attention to it.

(That advice has been repeated in this new thread. I wonder if you'll pay any attention this time?)

DON'T spam the forum with multiple threads for the same problem. It wastes everyone's time.
Topic archived. No new replies allowed.