Problem with Linked List Example

I've been working through "Data Structures with C++" by D.S. Malik and am having a problem with some of the source provided with the book while trying to understand the linked list. I do understand the concept of the linked lists, but I was trying out the examples without success. I have looked for errata and found nothing.

I'm receiving errors "'first' was not declared in this scope", "'last' was not declared in this scope" and "no post-increment operator for type". All of these variables are protected variables of a base class "linkedList.h" and are used in a derived class "orderedLinkedList.h".

This leads me to believe there is a problem with inheritance, but moving them to "public" did not yield any better results.

Any assistance would be greatly appreciated.

Below are three files included with the books source files, unmodified:

Pastbin entries:

linkedList.h - http://pastebin.com/V1cjatFU
orderedLinkedList.h - http://pastebin.com/rH0y8T0B
main.cpp - http://pastebin.com/75bcsmVN
What line?
The first error is on line #57 of orderedLinkedList.h, then pretty much everywhere first/last/count are referenced in orderedLinkedList.h.
I'm having a hard time seeing the problem. What happens if you chance line 57 to current=this->first;?
Ok. Updating all references to the protected members to this-> allowed the program to compile and executes properly.

Now my question is, why is this necessary for a derived class?

It shouldn't be necessary. What compiler are you using?

EDIT: Another good reason to always use this explicitly.
Last edited on
@helios

XCode 4.x
QT Creator 2.2.0

Both use g++ v4.2.1 (Apple Build 5666)

I'm currently on OSX, but I assume it'll do the same thing on my ubuntu workstation.

@m4ster r0shi

Thanks for the informative link. This does help it make sense as the base class is a template.

Topic archived. No new replies allowed.