1
votes

I'm trying to get an example from a book to work and im getting this error in 1 of the 3 files

.h

#ifndef H_unorderedArrayListType
#define H_unorderedArrayListType

template <class elemType>
class unorderedArrayListType
{
public:
       void insertAt(int location, const elemType& insertItem);
       void insertEnd(const elemType& insertitem);
       void replaceAt(int location, const elemType& repitem);
       void retrieveAt(int location, const elemType& repitem);
       int seqSearch(const elemType& searchItem) const;
       void remove(const elemType& removeItem);

       void sort();
       int binSearch(const elemType& item) const;

       unorderedArrayListType(int size = 100);
};
#endif

.cpp

#include "unorderedArrayListType.h"

template <class elemType>
int unorderedArrayListType<elemType>::binSearch(const elemType& item) const
{
    return binarySearch(list, length, item);
}

template <class elemType>
void unorderedArrayListType<elemType>::sort()
{
     selectionSort(list, length);
}

unorderedArrayListType::binSearch(const elemType&) const'

6 error: 'list' was not declared in this scope

6 error: 'length' was not declared in this scope

In member function 'void unorderedArrayListType::sort()':

12 error: 'list' was not declared in this scope

12 error: 'length' was not declared in this scope

12 error: there are no arguments to 'selectionSort' that depend on a template parameter, so a declaration of 'selectionSort' must be available [-fpermissive]

12 note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

|=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

1
As the error message says, you are using list, but you haven't declared it anywhere. Could be a mistake in the book, or you missed something.The Dark
First of all: don't put class template member function definitions into a cpp file. It wont work. The second thing is that list and length just don't seem to be defined anywhere. Should they possibly be member variables?pmr

1 Answers

0
votes

Looks like the code is incomplete. These functions are trying to access a member variable called 'list', which isn't defined in the code you've posted.

My guess is the code was meant to be pseudocode, or just a snippet of a work-in-progress.