unresolved token error using template<class t>

What i am trying to create is a library that creates an essentially resize-able array via a pointer array, this method is called a bucket list, but for some reason im having issues with a token error

Errors:

Error 1 error LNK2020: unresolved token (06000001) array.bucketlist<int>::.ctor C:\Users\debbie\Desktop\Documents\Visual Studio 2010\Projects\arrays\arrays\Main.obj

Error 2 error LNK2020: unresolved token (06000002) array.bucketlist<int>::~bucketlist<int> C:\Users\debbie\Desktop\Documents\Visual Studio 2010\Projects\arrays\arrays\Main.obj

Error 3 error LNK2020: unresolved token (06000003) array.bucketlist<int>::op_Subscript C:\Users\debbie\Desktop\Documents\Visual Studio 2010\Projects\arrays\arrays\Main.obj

Error 4 error LNK2020: unresolved token (06000004) array.bucketlist<int>::Size C:\Users\debbie\Desktop\Documents\Visual Studio 2010\Projects\arrays\arrays\Main.obj

Code:

Main.cpp (entry point)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "Stdafx.h"
#include "array.h"
#include <iostream>

using namespace array;
using namespace std;

int main ()
{
	bucketlist<int> intbl (5);
	for (int x = 0; x < 30; x++)
	{
		intbl[x] = x;
		cout << x << " was added correctly.\nThe array size is now: " << intbl.Size() << endl << endl;
	}

	system("Pause");
	return 0;
}


array.h (bucketlist class)
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
// arrays.h

#ifndef ARRAY_H
#define ARRAY_H

namespace array
{
	template<class _TYPE>
	ref class bucketlist
	{
	public:
		bucketlist ();
			//Default Constructor

		~bucketlist ();
			//Default Destructor

		bucketlist (int);
			//Overloaded Constructor
			//@param int - the size of each list that is added (default is 100)

		void resize (int);
			//bucketlist<_TYPE>::resize - resizes the array to the given value, done in increments of this->ListSize();
			//@param int - the new size of the array

		_TYPE& operator[] (unsigned int);
			//bucketlist<_TYPE>::operator[] - gets the value in the given index
			//@param unsigned int - the index being used
			//@return _TYPE& - the address of the requested index

		unsigned int Size ();
			//bucketlist<_TYPE>::Size - the size of the array
		
	protected:
		_TYPE **value;

		unsigned int size,
			listSize;

	};
}

#endif 


array.cpp (bucketlist class 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
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
// This is the main DLL file.

#include "stdafx.h"

#include "array.h"

template<class _TYPE>
array::bucketlist<_TYPE>::bucketlist ()
{
	this->listSize = 100;
	this->size = 2;
	this->value = &(new *_TYPE [2]);
	*this->value = &(new _TYPE [this->listSize]);
	*(this->value + 1) = &(new _TYPE [this->listSize]);
}

template<class _TYPE>
array::bucketlist<_TYPE>::~bucketlist ()
{
	for (int x = 0; x < this->size; x++)
		delete[] *(*(this->value + x))
}

template<class _TYPE>
array::bucketlist<_TYPE>::bucketlist (int _LIST_SIZE)
{
	this->listSize = _LIST_SIZE;
	this->size = 2;
	this->value = &(new *_TYPE [2]);
	*this->value = &(new _TYPE [this->listSize]);
	*(this->value + 1) = &(new _TYPE [this->listSize]);
}

template<class _TYPE>
_TYPE& array::bucketlist<_TYPE>::operator[] (unsigned int arr)
{
	if (arr > (size * listSize))
	{
		int tempSize = size;
		this->size *= this->size;
		_TYPE *tempArray[tempSize] = *this->value;
		this->value = &(new *_TYPE [this->size]);
		for (int x = 0; x < tempSize; x++)
			*(this->value + x) = tempArray[x];
		for (int x = tempSize; x < this->size; x++)
			*(this->value + x) = nullptr;
	}
	if (*(this->value + (arr / this->listSize)) == nullptr)
		*(this->value + (arr / this->listSize)) = &(new _TYPE [this->listSize]);

	return *(*(this->value + (arr / this->listSize)) + (arr % this->listSize))
}

template<class _TYPE>
void array::bucketlist<_TYPE>::resize (int size)
{
	size /= this->listSize;
	if (this->listSize > size)
	{
		int tempSize = this->size;
		this->size = size;
		_TYPE *tempArray[tempSize] = *this->value;
		this->value = &(new *_TYPE [this->size]);
		for (int x = 0; x < size; x++)
			*(this->value + x) = tempArray[x];
		for (int x = size; x < tempSize; x++)
			delete[] *(tempArray[x])
	}
	else if (this->listSize < size)
	{
		int tempSize = this->size;
		this->size = size;
		_TYPE *tempArray[tempSize] = *this->value;
		this->value = &(new *_TYPE [this->size]);
		for (int x = 0; x < tempSize; x++)
			*(this->value + x) = tempArray[x];
		for (int x = tempSize; x < this->size; x++)
			*(this->value + x) = nullptr;
	}
}

template<class _TYPE>
unsigned int array::bucketlist<_TYPE>::Size ()
{
	return (this->size * this->listSize);
}
Last edited on
You can't separate the implementation in templates.
Put all in the header or check out explicit template instantiation.

this->value = &(new *_TYPE [2]); should not compile, you are trying to get the address of a temporary.
Bleh so basically put it in the header?
And is there a way to get the address that won't cause it to be deallocated at the end of the scope?

And btw... thanks for the help
Last edited on
this->value = new *_TYPE[2];
IIRC identifiers starting with underscore and uppercase are reserved by the compiler
Topic archived. No new replies allowed.