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
#ifndef LINKEDLISTTYPE_H
#define LINKEDLISTTYPE_H
#include <iostream>
usingnamespace 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;
virtualbool search(const Type& searchItem) const = 0;
virtualvoid insertFirst(const Type& newItem) = 0;
virtualvoid insertLast(const Type& newItem) = 0;
virtualvoid 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;
}