container class problems

I've been trying to make a dynamic array template class recently and i've run into some problems on witch i have no idea how to fix so here is the code...

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef DYNAMICARRAY_H
#define DYNAMICARRAY_H

template<typename c_type>
class dynamicArray
{
	c_type * theArray;
	int m_max;
public:
	//The Constructor
	dynamicArray(int arraySize) : m_max(arraySize), theArray(NULL)
	{
		theArray = new c_type [arraySize];
		if(theArray==0)
		{
			return;
		}
		for(int a=0; a<arraySize; a++)
		{
			theArray[a]=0;
		}
		m_max=arraySize;
	}
	//Another constructor
	dynamicArray() : m_max(0), theArray(NULL)
	{
		//ya....
	}
	//The Destructor
	~dynamicArray()
	{
		delete [] theArray;
	}
	//Function to delete the Dynamic array
	void erase()
	{
		delete [] theArray;
		theArray=NULL;
		m_max=0;
	}
	//set the size of the dynamic array before it's been allocated
	void allocate(int size, bool changeMax = true)
	{
		theArray = new c_type [size];
		if(theArray==0)
		{
			return;
		}
		for(int a=0; a<size; a++)
		{
			theArray[a]=0;
		}
		if(changeMax)
			m_max=size;
	}
	//This will wipe the dynamic array and reszie it, basicly reseting it
	void reallocate(int size)
	{
		erase();
		allocate(size);
	}
	//this will change the size of the currently allocated dynamic array
	void resize(int size)
	{
		c_type * backup = NULL;
		backup = new c_type [max];
		if(backup==0)
		{
			return;
		}
		for(int a=0; a<m_max; a++)
		{
			backup[a]=theArray[a];
		}
		erase();
		allocate(size, false);
		for(int a=0; a<m_max; a++)
		{
			theArray[a]=backup[a];
		}
		for(int a=m_max; a<size; a++)
		{
			theArray[a]=0;
		}
		delete [] backup;
		m_max=size;
	}
	//get the length of the array
	int getLength()
	{
		return m_max;
	}
	//overload the [] operator so you can access the values as such
	c_type& operator[](int value)
	{
		if(value<0 || value>m_max)
			return theArray[0];
		return theArray[value];
	}
	//copy another dynamic array into this one
	void copy(dynamicArray<c_type> &reference)
	{
		erase();
		allocate(reference.getLength());
		for(int a=0; a<m_max; a++)
			theArray[a]=reference[a];
	}
};

#endif 


while the errors i'm getting are as follows:

1
2
3
4
5
6
7
8
9
10
11
12
1>          c:\users\cory powell\documents\visual studio 2010\projects\random map design\random map design\dynamicarray.h(66): error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'unsigned int'
1>          Context does not allow for disambiguation of overloaded function
1>          c:\users\cory powell\documents\visual studio 2010\projects\random map design\random map design\dynamicarray.h(64) : while compiling class template member function 'void dynamicArray<c_type>::resize(int)'
1>          with
1>          [
1>              c_type=keyItem
1>          ]
1>          c:\users\cory powell\documents\visual studio 2010\projects\random map design\random map design\map.h(11) : see reference to class template instantiation 'dynamicArray<c_type>' being compiled
1>          with
1>          [
1>              c_type=keyItem
1>          ]
Should line 66 read "backup = new c_type [size];"?
Should line 66 read "backup = new c_type [size];"?


no but you saying that somehow pointed me out to my stupid mistake of saying max instead of m_max...but now i have lots of linker errors...time to get working....
Topic archived. No new replies allowed.