Hey guys, anyone mind helping, I'd really appreciate it.
I'm getting an error, access violation according to MSVC6, and I've used cout/endl debugging method to show which method its in.
Code:
template< typename Datatype >
int Array<Datatype>::Resize (USHORT p_sizeChanged)
{
Datatype* tempArray = new Datatype[p_sizeChanged];
if (tempArray == 0) {
std::cout << "Could not allocate enough memory." << std::endl;
return -1;
}
USHORT* reSized;
if (p_sizeChanged < m_size) {
std::cout << "DEBUG 2" << std::endl;
*reSized = p_sizeChanged;
} else if (p_sizeChanged > m_size) {
std::cout << "DEBUG 2++" << std::endl;
*reSized = m_size;
} else {
std::cout << "Could not figure out the changed array size." << std::endl;
return -1;
}
for (USHORT index = 0; index < *reSized; ++index)
tempArray[index] = m_array[index];
m_size = p_sizeChanged;
if (m_array != 0)
delete[] m_array;
m_array = tempArray;
tempArray = 0;
return 0;
}
int main ()
{
Array<int> listLevels(10);
USHORT index;
for (index = 0; index < 10; ++index) {
listLevels[index] = index;
}
listLevels.Display ();
std::cout << "DEBUG 1" << std::endl;
std::cin.get ();
//increase the size of the array with Renew.
listLevels.Resize (30);
std::cout << "DEBUG 3" << std::endl;
}
The Array class is in a .h file, and I'm using templates for the class so I had to use a template for the method thats in a different file. It doesnt get further than:
std::cout << "DEBUG 2++" << std::endl;
in the Resize method. I'm assuming its angry with me trying to access the private variable of the class: m_size. If it is, that really annoys me.. I mean if its going to pull some violation error because I'm using templates then what the hell is the point of them. Unless an error is occuring because of Datatype being unaccessible? since the method is seperated from the class and its templated.
Either way.. templates are starting to ........ me off.