Does anyone know why I can't access the protected data members of the base class linkedListType in the member functions of my derived class unorderedLinkedList??
template<class elemType>
void unorderedLinkedList<elemType>::sortGuestByLastName()
{
int i, j;
int smallestIndex;
string firstName_1;
string firstName_2;
string lastName_1;
string lastName_2;
elemType temp;
nodeType<elemType> *smallestNode;
nodeType<elemType> *current;
nodeType<elemType> *trailCurrent;
for (trailCurrent = first; trailCurrent != last; trailCurrent = trailCurrent->link)
{
smallestNode = trailCurrent;
for (current = trailCurrent->link; current != NULL; current = current->link)
{
current->info.getName(firstName_1, lastName_1); //fn getname(), whose definition is unshown, is defined
//for a class whose object is the data part of the node
smallestNode->info.getName(firstName_2, lastName_2);
if (lastName_1 < lastName_2)
smallestNode = current;
}
//trailCurrent->info.swap(smallestNode->info);
temp = trailCurrent->info;
trailCurrent->info = smallestNode->info;
smallestNode->info = temp;
}
}
When I tried to compile the program, I got the message below regarding the sort function:
In member function `void unorderedLinkedList<elemType>::sortGuestByLastName()':
error: `first' undeclared (first use this function)
error: (Each undeclared identifier is reported only once for each function it appears in.)
error: `last' undeclared (first use this function)
It's baffling why I couldn't access the protected member variables first and last of the base class from the member functions of the derived class!! This pattern happened across several other derived class functions, also. Why is this so?
Your suggestion solved the problem. But I'm still astonished that the members of the derived class could not access the protected member variables of the base class without using the this pointer, in this case. I have written programs where such protected data members are visible/accessible. It's not like the data members are private; for then, I would understand why they are inaccessible. But, they are protected!! This conflicts with the concepts of inheritance I've read anywhere.