Problem with inheritance

Im creating a linked list class, but i cant seem to be able to transer the protected members of my base class linkedListType to my class unorderedLinkedList. Here's the error i get:

J:\C++\LinkedListClass\unorderedLinkedList.h||In member function 'bool unorderedLinkedList<Type>::search(const Type&) const':|
J:\C++\LinkedListClass\unorderedLinkedList.h|36|error: 'first' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h||In member function 'void unorderedLinkedList<Type>::insertFirst(const Type&)':|
J:\C++\LinkedListClass\unorderedLinkedList.h|54|error: 'first' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|56|error: 'count' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|57|error: 'last' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h||In member function 'void unorderedLinkedList<Type>::deleteNode(const Type&)':|
J:\C++\LinkedListClass\unorderedLinkedList.h|68|error: 'first' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|78|error: 'count' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|80|error: 'last' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|105|error: 'count' was not declared in this scope|
J:\C++\LinkedListClass\unorderedLinkedList.h|107|error: 'last' was not declared in this scope|
||=== Build finished: 9 errors, 0 warnings ===|



unorderedLinkedList.h
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_INCLUDED
#define UNORDEREDLINKEDLIST_H_INCLUDED

#include "linkedListType.h"
#include <iostream>
template<class Type>
class unorderedLinkedList: public linkedListType<Type>
{
    public:
        bool search(const Type& searchItem) const;
        //function to determine whether searthItem is in the list.
                    //return true of search item is in the
                    //list, otherwise the value false is
                    //returned
        void insertFirst(const Type& newItem);
        //function to insert newitem at the beginning of the list
                    //first points to the new list, new item is
                    //inserted at the beg. of the list, last
                    //points to the last node in the list
        void insertLast(const Type& newItem);
        //function to insert newItem at end of list
                    //first points to new list, newItem
                    //is inserted at end of list, last points
                    //to the last node in the list, count inc.
        void deleteNode(const Type& deleteItem);
        //function to delete item from the list
                    //if found, node containing
                    //item is deleted from list
};

template<class Type>
bool unorderedLinkedList<Type>::search(const Type& searchItem) const
{
    nodeType<Type> *current;    //pointer to traverse list
    bool found = false;         //runs while loop
    current = first;            //set current to point to the first node
    while(current != NULL && !found)
    {
        if(current->info == searchItem) //if search item found
            found = true;               //terminate while loop
        else
            current = current->link;     //advance to next node
    }

    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>;   //create new node
    newNode->info = newItem;        //store new item in node
    newNode->link = first;          //insert newNode before first
    first = newNode;                //make first point to newNode
    count++;                        //incr.
    if(last == NULL)                //if list is empty
        last = newNode;
}

template<class Type>
void unorderedLinkedList<Type>::deleteNode(const Type& deleteItem)
{
    nodeType<Type> *current;
    nodeType<Type> *trailCurrent;
    bool found;

    if(first == NULL)
        std::cout << "Cannot delete from an empty list...\n";
    else
    {
        ///CASE TWO
        if(first ->info == deleteItem)
        ///--------
        {
            current = first;        //get address to be deleted
            first = first->link;
            count--;
            if(first == NULL)       //if list with one node
                last = NULL;
            delete current;
        }
        else
        {
            found = false;
            trailCurrent = first;   //set trailCurrent to point
                                    //to the first node
            current = first->link;  //set current to point to second node

            while(current != NULL && !found)
            {
                if(current->info != deleteItem)
                {
                    trailCurrent = current;
                    current = current->link;
                }
                else
                    found = true;
            }
            ///CASE THREE
            if(found)
            ///---------
            {
                trailCurrent->link = current->link;
                count--;

                if(last == current)
                    last = trailCurrent;
                delete current;
            }
            else
                std::cout << "Item to be deleted not found in list...\n";
        }
    }
}

#endif // UNORDEREDLINKEDLIST_H_INCLUDED


LinkedListType.h
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
#ifndef LINKEDLISTTYPE_H_INCLUDED
#define LINKEDLISTTYPE_H_INCLUDED

#include "linkedListIterator.h"

template<class Type>
class linkedListType
{
    public:
        const linkedListType<Type>& operator=
                                (const linkedListType<Type>&);
        //overload assignment operator
        void initializeList();
        //Initialize list to empty state
        //first = NULL, last = NULL, count = 0
        bool isEmptyList() const;
        //determine whether list is empty
        //returns true if the list is empty
        void print() const;
        //output data
        int length() const;
        //return number of nodes from list
        //value of count returned
        void destroyList();
        //function to return first element from list
        //first = NULL, last = NULL, count = 0
        Type front() const;
        //returns first element of list
        //if list is empty, program terminates
        Type back() const;
        //return last element of list
        //if list is empty, program terminates
        virtual bool search(const Type& searchItem) const = 0;
        //PURE VIRTUAL FUNCTION, must be overridden
        //returns true if item is in list, false if not
        virtual void insertFirst(const Type& newItem) = 0;
        //inset new item as beginning of list
        //first points to new list, new item is
        //inserted at beg. of list, last points
        //to last node, count incremented
        virtual void insertLast(const Type& newItem) = 0;
        //insert new item at end of list
        //first points to new list, new
        //item instered at end of list and
        //points to last
        virtual void deleteNode(const Type& deleteItem) = 0;
        //delete item from list
        //count decremented by one, nodes set correctly
        linkedListIterator<Type> begin();
        //function to return an iterator at the
        //begining of the linked list
        //returns an iterator set to first
        linkedListIterator<Type> end();
        //function to return iterator type
        //that points to end of linked list
        linkedListType();
        //defualt constructor
        //list empty state
        //first = NULL, last = NULL, count = 0
        linkedListType(const linkedListType<Type>& otherList);
        //copy constructor
        ~linkedListType();
        //destructor
        //deletes all nodes from list
    protected:
        int count;  //stores amount of elements in list
        nodeType<Type> *first; //pointer to the first node of the list
        nodeType<Type> *last;  //pointer to last node in list
    private:
        void copyList(const linkedListType<Type>& otherList);
        //function to make a copy of other list
        //copy of other list is created and assigned to current list
};
    //function code here, not enough room to put it so i edited it out, but functions work.
#endif // LINKEDLISTTYPE_H_INCLUDED 
Use either the pointer this or YourBaseClassName:: before any member of the base class that is referenced in the derived class.
Last edited on
Thanks a ton vlad! program is working now , appreciate such a quick respone.
Topic archived. No new replies allowed.