My heap sort keeps on crashing (C++)

Started by
11 comments, last by BitMaster 11 years ago

You're passing your Array object to the PrintArray function by value rather than by reference. As a result the parameter is a copy of the passed in argument (and therefore its m_array member points to the same address), so when the destructor is invoked at the end of the function the memory pointed to by both instances is deleted.

Advertisement

Wow, it finally worked. You guys were right, it was the PrintArray function not taking a reference to an array.

Once again, you guys are truly awesome. Thank you

Since your Array class does not implement proper copy semantics you should explicitly delete the copy constructor and assignment operator (in C++11) or set them private (before C++11) to prevent an accidental copy (which never works with that class).

Considering how far your Array class is behind std::vector (both regarding features and correctness in other aspects) I would also strongly suggest that you either make implementing a proper array class the whole point of the learning experience (not as simple as it sounds) or using std::vector.

On a more personal note, if I ever catch you "using namespace std;" at the top of a header I'm forced to use or work with, I will hunt you down.

This topic is closed to new replies.

Advertisement