Unresolved external symbol

Hello! I'm running into a problem with my assignment. I'm trying to make a ring class with a template and a base class. This is my header.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include "LinkedSortedList.h"

template<class itemType>
class Ring :
	public LinkedSortedList<itemType>
{
public:
	Ring();
	~Ring();
	void insert(const itemType&);
	void deleteItem(const itemType&);
	void display();
};


And this is my .cpp file.

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
#include "Ring.h"


template<class itemType>
Ring<itemType>::Ring()
{
} // default constructor


template<class itemType>
Ring<itemType>::~Ring()
{
} // default destructor

template<class itemType>
void Ring<itemType>::insert(const itemType& item) {
	LinkedSortedList<itemType>::insertSorted(item);
}

template<class itemType>
void Ring<itemType>::deleteItem(const itemType& item) {
	LinkedSortedList<itemType>::removeSorted(item);
}

template<class itemType>
void Ring<itemType>::display() {
	cout << "The sorted list contains " << endl;
	for (int pos = 1; pos <= LinkedSortedList<itemType>::getLength(); pos++)
	{
		cout << LinkedSortedList<itemType>::getEntry(pos) << " ";
	} // end for
}


But when I make a new object in main and run them, I get these errors.

Error LNK2019 unresolved external symbol "public: __thiscall Ring<int>::Ring<int>(void)" (??0?$Ring@H@@QAE@XZ) referenced in function _main LinkedSortedList

Error LNK2019 unresolved external symbol "public: void __thiscall Ring<int>::insert(int const &)" (?insert@?$Ring@H@@QAEXABH@Z) referenced in function _main LinkedSortedList

I thought I got the templates and everything working. Is it the base class that's the problem? I worked with the base class by itself and it works fine.

Please help.
Never mind. In the main file, add both the .h file and the .cpp file to avoid error LNK2019
closed account (E0p9LyTq)
You should never include a .cpp file in another one, only include header files.

You are creating a template, all your code should be in your header file.
Last edited on
Topic archived. No new replies allowed.