I am writing a program that allows for the creation of a theoretically infinitely large integer. I have created the class MyInt and implemented the storage using DMA.
I have attached the .cpp and .h files. These are not the complete files, there are several other overloads but for simplocity sake I narrowed it down to only those functions involved in the problem.
I have placed many cout statements in here trying to trace the problem. And the problem seems to be in the Grow() function that increases the size of the array. Any help would be greatly appreciated.
It's an assignment. They don't want you using things that might make your life too easy. I still can't use the string class much less vectors. I have tried putting the  in there and it doesn't work either. I have tried everything I can think of. I have never been so stumped. There error I am getting starts with this, and then the "memory map" which I am not experienced enough to understand.
It crashes when it tries to use delete. From the research I have done this error is often times caused by trying to delete an object/variable that was not created using new. Not sure I can see how that is the case here. It seems like amybe I am doing something wrong in line 178 where this is:
unsigned int *newArray = new unsigned int[maxSize];
It's an assignment. They don't want you using things that might make your life too easy.
Using container and string classes make things easier in terms of having working components that you can use to build the larger application. However, you still have to write the program using these components, so that part is still not "easy", but at least your thinking is now geared towards solving the actual problem that needs to be solved.
Having said that, C++ beginner courses that still teach C++ as if it's 1990 and not 2010 should be abolished (if I had my way). It's the year 2010, and string classes, vectors, etc. have been standardized in C++ since 1998. I wish these courses were honest, and say you are learning 'C' and not C++.
Thanks Paul, actually most of that code block came from an example program from my proffessor. I will take a look at it again and see if I can find something. I had to take a break starting to see cross eyed and want to break stuff, just kidding. Thanks again, I will post what I find when I look at it.
It's an assignment. They don't want you using things that might make your life too easy. I still can't use the string class much less vectors.
When you think you've got the hang of dynamic memory allocation, then maybe you could write you own simple string and vector classes and use them in future assignments that ban the STL. They can't complain about that!
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
I have actually considered that. I wasn't sure which would be more work though, writting the vector and string classes or just using the libraries permitted. Next semester I'm taking data structures and algorithms. Apparently in that class they introduce the STL so I'm guessing at that point we will be able to use more of the libraries.
In the prereq course intro to c++ we weren't even alowwed to use iomanip or cctype. We had to use ios:: to format output. I understand why they did it this way it's kind of like in math they didn't want you to use a calculator until you got to a certain level. It's just frustrating to know there is a tool that could make what I am trying to do allot easier.
I was actually dreaming about this program last night. I think I got something, but I need to take a look at it first.
I understand why they did it this way it's kind of like in math they didn't want you to use a calculator until you got to a certain level.
That would be a defensible argument (though I still won't agree with it) iff you were taught to write completely safe programs. But as Paul has pointed out, the code provided by your professor is not safe. Hence, you are simply being taught bad programming practices, rather than the basics.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
I changed the overload of the assignment operator to reflect what Paul McKenzie suggested. I am still getting the same error though. I am going to stop by one of my teching assistants offices today at school. But I have to say, I don't have allot of faith in those guys.
const MyInt MyInt:perator= (const MyInt& n)
if(this != &n)
// Create an array to copy data to before deleting intArray
// in case an exception is thrown.
unsigned int *temp = new unsigned int[n.currentSize];
for(int i = 0; i < n.currentSize; i++)
temp[i] = n.intArray[i];
// Delete the old array.
delete  intArray;
// Assign the new array pointer to original.
intArray = temp;
// Assign the size information.
currentSize = n.currentSize;
maxSize = n.maxSize;