If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

new [] / delete [] errors, going crazy!

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.

Re: new [] / delete [] errors, going crazy!

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:

Re: new [] / delete [] errors, going crazy!

Originally Posted by weaverx9x9

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++.

Re: new [] / delete [] errors, going crazy!

Re: new [] / delete [] errors, going crazy!

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.

Re: new [] / delete [] errors, going crazy!

Originally Posted by weaverx9x9

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!

Re: new [] / delete [] errors, going crazy!

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.

Re: new [] / delete [] errors, going crazy!

Originally Posted by weaverx9x9

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

Re: new [] / delete [] errors, going crazy!

Yeah that's true D_Drmmr.

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.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.