struct members declared in base class that are used in derived class are "not declared in that scope"

The 3 protected members in the base class are used in the derived class . Error message says they are not declared in the scope. Strangely, the struct members declared in the base class appears in red throughout the program? Any guidance on this would be great
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
#ifndef LINKEDLISTTYPE_H
#define LINKEDLISTTYPE_H
#include <iostream>
using namespace std;
//Definition of the node
template <class Type>
struct nodeType
{
    Type info;
    nodeType<Type> *link;
};
template <class Type>
class linkedListType
{
public:
    const linkedListType<Type>& operator=(const linkedListType<Type>&);
   void initializeList();
    bool isEmptyList() const;
    void print() const;
     int length() const;
    void destroyList();
    Type front() const;
    Type back() const;
    virtual bool search(const Type& searchItem) const = 0;
    virtual void insertFirst(const Type& newItem) = 0;
    virtual void insertLast(const Type& newItem) = 0;
    virtual void deleteNode(const Type& deleteItem) = 0;
    linkedListType();
    linkedListType(const linkedListType<Type>& otherList);
     ~linkedListType();
     void divideAt(linkedListType<Type> &secondList, const Type& item);
protected:
    int count; //variable to store the number of elements in the list
    nodeType<Type> *first; //pointer to the first node of the list
    nodeType<Type> *last; //pointer to the last node of the list
private:
    void copyList(const linkedListType<Type>& otherList);
    //Function to make a copy of otherList.
    //Postcondition: A copy of otherList is created and assigned
    // to this list.
};

#endif // LINKEDLISTTYPE_H

template <class Type>
bool linkedListType<Type>::isEmptyList() const
{
return (first == NULL);
}
template <class Type>
linkedListType<Type>::linkedListType() //default constructor
{
        first = NULL;
        last = NULL;
        count = 0;
}
template <class Type>
void linkedListType<Type>::destroyList()
{
nodeType<Type> *temp;               
                                    
while (first != NULL)               
{
    temp = first;                       
    first = first->link;                
    delete temp;                        
}
    last = NULL;                        
                                        
    count = 0;
}
template <class Type>
void linkedListType<Type>::initializeList()
{
destroyList();                      
}
template <class Type>
void linkedListType<Type>::print() const
{
nodeType<Type> *current;            
current = first;                    
while (current != NULL)             
{
cout << current->info << " ";
current = current->link;
}
}                                   //end print

template <class Type>
int linkedListType<Type>::length() const
{
return count;
}
template <class Type>
Type linkedListType<Type>::front() const
{
assert(first != NULL);
return first->info;               
}                                 
template <class Type>
Type linkedListType<Type>::back() const
{
assert(last != NULL);
return last->info;                  //return the info of the last node
}                                   //end back

/*template <class Type>
linkedListIterator<Type> linkedListType<Type>::begin()
{
linkedListIterator<Type> temp(first);
return temp;
}
template <class Type>
linkedListIterator<Type> linkedListType<Type>::end()
{
linkedListIterator<Type> temp(NULL);
return temp;
}*/
template <class Type>
void linkedListType<Type>::copyList
(const linkedListType<Type>& otherList)
{
nodeType<Type> *newNode; //pointer to create a node
nodeType<Type> *current; //pointer to traverse the list
if (first != NULL) //if the list is nonempty, make it empty
destroyList();
if (otherList.first == NULL) //otherList is empty
{
first = NULL;
last = NULL;
count = 0;
}
else
{
current = otherList.first; //current points to the
count = otherList.count;
first = new nodeType<Type>; //create the node
first->info = current->info; //copy the info
first->link = NULL; //set the link field of the node to NULL
last = first; //make last point to the first node
current = current->link; //make current point to the next
while (current != NULL)
{
newNode = new nodeType<Type>; //create a node
newNode->info = current->info; //copy the info
newNode->link = NULL; //set the link of newNode to NULL
last->link = newNode; //attach newNode after last
last = newNode; //make last point to the actual last
//node
current = current->link; //make current point to the
//next node
}//end while
}//end else
}//end copyList
template <class Type>
linkedListType<Type>::~linkedListType() //destructor
{
destroyList();
}
template <class Type>
linkedListType<Type>::linkedListType(const linkedListType<Type>& otherList)
{
first = NULL;
copyList(otherList);
template <class Type>
const linkedListType<Type>& linkedListType<Type>::operator=
(const linkedListType<Type>& otherList)
{
if (this != &otherList) //avoid self-copy
{
copyList(otherList);
}//end else
return *this;
}

template <class Type>
void linkedListType<Type>::divideAt(linkedListType<Type> &secondList, const Type& item)
{
nodeType<Type> *current;
nodeType<Type> *previousCurrent;
previousCurrent = first;
current = first->link;
if(count = 0) //No need to divide
return;
if(previousCurrent->info == item) 
{
secondList->first = first;
secondList->last = last;
secondList->count = count;
first = NULL;
last = NULL;
count = 0;
}
int i = 1;
while(current != NULL)
{
if(current->info = item)
break;
previousCurrent = current;
current = current->link;
i++;
}
if(current == NULL) 
return;
secondList->last = last;
last = previousCurrent;
secondList->first = current;
last->link = NULL;
secondList->count = count - i;
count = i;
}


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
#ifndef UNORDEREDLINKEDLIST_H
#define UNORDEREDLINKEDLIST_H

#include "linkedlisttype.h"
template <class Type>
class unorderedLinkedList: public linkedListType<Type>
{
public:
        bool search(const Type& searchItem) const;
        void insertFirst(const Type& newItem);
      
        void insertLast(const Type& newItem);
        
        void deleteNode(const Type& deleteItem);
  };

#endif 

template <class Type>
bool unorderedLinkedList<Type>::search(const Type& searchItem) const
{
        nodeType<Type> *current; 
        bool found = false;
        current = first; 
        while (current != NULL && !found) 
        if (current->info == searchItem) 
        found = true;
        else
        current = current->link; 
        return found;

template <class Type>
void unorderedLinkedList<Type>::insertFirst(const Type& newItem)
{
nodeType<Type> *newNode; //pointer to create the new node
newNode = new nodeType<Type>; 
newNode->info = newItem; 
newNode->link = first; 
first = newNode;
count++; //increment count
if (last == NULL) 
//the last node in the list
last = newNode;
}//end insertFirst

template <class Type>
void unorderedLinkedList<Type>::insertLast(const Type& newItem)
{
nodeType<Type> *newNode; 
newNode = new nodeType<Type>; 
newNode->info = newItem; 
newNode->link = NULL; 
if (first == NULL) 
//both the first and last node
{
first = newNode;
last = newNode;
count++; //increment count
}
else 
{
last->link = newNode; 
last = newNode; 
//last node in the list
count++; 
}
}//end insertLast
template <class Type>
void unorderedLinkedList<Type>::deleteNode(const Type& deleteItem)
{
nodeType<Type> *current; 
nodeType<Type> *trailCurrent; 
bool found;
if (first == NULL) 
cout << "Cannot delete from an empty list."
<< endl;
else
{
if (first->info == deleteItem) 
{
current = first;
first = first->link;
count--;
if (first == NULL) 
last = NULL;
delete current;
}
else 
{
found = false;
trailCurrent = first; 
//to the first node
current = first->link; 
//the second node
while (current != NULL && !found)
{
if (current->info != deleteItem)
{
trailCurrent = current;
current = current-> link;
}
else
found = true;
}//end while
if (found) //Case 3; if found, delete the node
{
trailCurrent->link = current->link;
count--;
if (last == current) 
last = trailCurrent; 
delete current; 
}
else
cout << "The item to be deleted is not in "
<< "the list." << endl;
}
}
}
Last edited on
- indent your code
- fix missing braces

prefix every member access with this->
or put using Base<Type>::member; in the class definition
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Name-lookup.html#Name-lookup


also, the function definitions should be inside the include guards.
Last edited on
Topic archived. No new replies allowed.