was not declared in this scope

I am learning C++. I am coming across a problem which I somewhat understand but I don't understand why it's giving me the error in this instance. I know it's probably something dumb that I haven't done or something I've missed but I can't find where I have gone wrong.

I have created a class called linked list and then used inheritance to create unorderedList from linked list. Any variables that I use in the child class says was not declared in this scope. The variables are protected and unorderedList recongises the variables but still give me this error. I hope I have posted this in the right place and someone is willing to help.

Regards,

Kyle

Below the 2 classes:

#ifndef LINKED_LISTS_LINKEDLIST_H
#define LINKED_LISTS_LINKEDLIST_H

#include <iostream>
using namespace std;

template <class Type>
struct node{
Type info;
node <Type> *next;
};


template<class Type>
class linkedList{
public:
const linkedList<Type>& operator=(const linkedList<Type>& );
linkedList();
linkedList(const linkedList<Type>& otherList);
~linkedList();
void initialiseList();
bool isEmpty() 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;

protected:
int count;
node<Type> *first;
node<Type> *last;

private:
void copyList(const linkedList<Type>& otherlist);
};

template<class Type>
const linkedList<Type> &linkedList<Type>::operator=(const linkedList<Type> & otherList) {
if (this != &otherList)
copyList(otherList);

return *this;
}

template<class Type>
linkedList<Type>::linkedList() {
first = NULL;
last = NULL;
count = 0;

}

template<class Type>
linkedList<Type>::linkedList(const linkedList<Type> &otherList) {
first = NULL;
copyList(otherList);

}

template<class Type>
void linkedList<Type>::initialiseList() {
destroyList();

}

template<class Type>
bool linkedList<Type>::isEmpty() const{
return (first == NULL);
}

template<class Type>
void linkedList<Type>::print() const {
node<Type> *current;

current = first;

while (current != NULL){
cout << current->info << " ";
current = current->next;
}

}

template<class Type>
int linkedList<Type>::length() const {
return count;
}

template<class Type>
void linkedList<Type>::destroyList() {
node<Type> *temp;

while(first != NULL){
temp = first;
first = first->next;
delete temp;
}
last = NULL;
count = 0;
}

template<class Type>
Type linkedList<Type>::front() const {
return first->info;
}

template<class Type>
Type linkedList<Type>::back() const {
return last->info;
}

template<class Type>
linkedList<Type>::~linkedList() {
destroyList();
}

template<class Type>
void linkedList<Type>::copyList(const linkedList<Type> &otherlist) {
node<Type> *newNode;
node<Type> *current;

if (first != NULL){
destroyList();
}

if (otherlist.first == NULL){
first = NULL;
last = NULL;
count = 0;
}
else{
current = otherlist.first;
count = otherlist.count;

first = new node<Type>;
first->info = current->info;
first->next = NULL;
last = first;
current = current->next;

while (current != NULL){
newNode = new node<Type>;
newNode->info = current->info;
newNode->next =NULL;
last->next = newNode;
last = newNode;
current = current->next;
}
}

}
#endif //LINKED_LISTS_LINKEDLIST_H

//
// Created by Kyle on 2017/02/07.
//

#ifndef LINKED_LISTS_UNORDEREDLIST_H
#define LINKED_LISTS_UNORDEREDLIST_H

#include "linkedList.h"
#include <iostream>
using namespace std;

template <class Type>
class unorderedList: public linkedList<Type>{
public:
bool search(const Type & searchItem) const;
void insertFirst(const Type& newItem);
void insertLast (const Type& newItem);
void deleteNode (const Type& deleteItem);
};


template <class Type>
bool unorderedList<Type>::search(const Type& searchItem) const{
node<Type> *current;
bool found = false;

current = first;

while (current != NULL && !found){
if (current->info == searchItem)
found = true;
else
current = current->next;
}
return found;
}

template <class Type>
void unorderedList<Type>::insertFirst(const Type &newItem) {
node<Type> *newNode;

newNode = new node<Type>;
newNode->info = newItem;
newNode->next = first;
first = newNode;

count++;
if (last == NULL)
last = newNode;
}

template <class Type>
void unorderedList<Type>::insertLast(const Type &newItem) {
node<Type> *newNode;
newNode = new node<Type>;

newNode->info = newItem;
newNode->next = NULL;

if (first == NULL){
first = newNode;
last = newNode;
count++;
}
else{
last->next = newNode;
last = newNode;
count++;
}

}

template <class Type>
void unorderedList<Type>::deleteNode(const Type &deleteItem) {
node<Type> * current;
node<Type> * trailer;
bool found;


if (first == NULL)
cout << "Cannot delete form an empty list.\n";
else{
if (first->info == deleteItem){
current = first;
first = first->next;
count--;
if (first == NULL)
last = NULL;

delete current;
}
else{
found = false;
trailer = first;
current = first->next;

while (current != NULL && !found){
if (current->info != deleteItem){
trailer = current;
current = current->next;
}
else
found = true;
}
if (found){
trailer->next = current->next;
count--;

if(current == last)
last = trailer;
delete current;
}
else
cout << "The item to be deleted is not in the list\n";
}
}
}
#endif //LINKED_LISTS_UNORDEREDLIST_H

 

0

请先登录再写评论。