template class function parameter errors

This is the class:

1
2
template<class _TYPE, class _VALUE = int>
class avltree;


This is the function:

1
2
template<class _TYPE, class _VALUE>
avltree<_TYPE, _VALUE>* avltree<_TYPE, _VALUE>::addValue (const _TYPE&);


and this is how im calling it:

1
2
3
4
5
6
TestClass * arr[5];
for (int x = 0; x < 5; x++)
{
    arr[x] = new TestClass (rand() % 1000, static_cast<double>(rand() % 100000) / 100.0); //these are the correct parameters for each initialization of TestClass
    TestClass::idTree.addValue (arr[x]); //TestClass::idTree is a avltree<TestClass*, int> variable
}


And these are the errors its giving me:

1
2
Error 1 error C2663: 'avltree<_TYPE>::addValue'
Error 2 IntelliSense: no instance of overloaded function "avltree<_TYPE, _VALUE>::addValue [with _TYPE=TestClass *, _VALUE=int]" matches the argument list and object (the object has type qualifiers that prevent a match)
Can you show how TestClass::idTree is defined?
its just: avltree<TestClass*, int> TestClass::idTree (GetId);

GetId is an unrelated function, the issue is the addValue function
Using the constructor with the GetId function supplies a function to determine the value of the class type, ie:
const int& GetId (const TestClass*& thisobj) { return thisobj->id; }

so that you can have multiple trees for one class without wasting your > < >= <= and == operators
Last edited on
Seems to work fine for me. Simplified version below. idTree is a static data member of TestClass I assume? It is also non-const?

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
#include <iostream>
#include <time.h>
#include <vector>
#include <cmath>
using namespace std;

template<class _TYPE, class _VALUE = int>
class avltree
{
public:
	void addValue (const _TYPE&)
	{
		cout << "addValue" << endl;
	}
};

class TestClass
{
public:
	static avltree<TestClass*, int> idTree;
};

avltree<TestClass*, int> TestClass::idTree;

void main()
{
	TestClass * arr[5];
	for (int i = 0; i < 5; i++)
	{
		arr[i] = new TestClass(); //these are the correct parameters for each initialization of TestClass
		TestClass::idTree.addValue (arr[i]); //TestClass::idTree is a avltree<TestClass*, int> variable
	}
}
Last edited on
Topic archived. No new replies allowed.