Question

SortedList.h is an abstract template, LinkedSortedList.h derives SortedList.h and is a template, and LinkedSortedList.cpp is a template implementing the functions in LinkedSortedList.h, and is where I'm having problems.

New New Errors: I believe my issue now is I'm not properly overiding the methods in SortedList.h.

Method in SortedList.h:

virtual void clear() = 0;   

Method in LinkedSortedList.h:

template <typename Elm> void SortedList<Elm>::clear() override; 

error:

error C3240: 'clear' : must be a non-overloaded abstract member function of 'SortedList'

I've tried:

void SortedList<Elm>::clear(){}

But I still get the same error. I've tried to find the solution, but have failed.

Was it helpful?

Solution

You need to tell the compiler that you are defining the member of a template:

template <typename Elm>
LinkedSortedList<Elm>::LinkedSortedList() {

EDIT: This is more like multiple questions, but the different error messages:

c:\users\deltac\documents\visual studio 2010\projects\linked list\linked list\linkedsortedlist.h(23): error C2365: 'LinkedSortedList::size' : redefinition; previous definition was 'member function'

From the code:

int size() const;
int size;           // Compiler report here?

You cannot use the same identifier to refer to a member variable and a member function. You can reuse the same identifier for different member functions (functions can be overloaded). Rename the member to something else: int m_size; for example.

Error 2 is not an error, but the continuation of the previous error message in the logs (lines that start with see don't indicate a new error.

c:\users\deltac\documents\visual studio 2010\projects\linked list\linked list\main.cpp(27): error C2259: 'LinkedSortedList' : cannot instantiate abstract class

There is at least one pure virtual function in the base (the full error message probably includes the list of them) that has not been overriden. This makes the derived type an abstract type and you cannot instantiate it. Provide the appropriate definitions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top