Programming in C++ is Not Humanly Possible

2004-05-30T20:31:00Z

Seriously, I cannot program in this language. It’s impossible. No human being can manage memory themselves. The task is just too difficult. I’ve been programming for as long as I can remember, and every time I try to write something in this God forsaken language it ends up horribly broken.

I have a class that takes an input image, modifies it, and writes an output image. I wanted to make another class to wrap around this one so that it can overwrite the input data with the output data. To do this, the class needs to have a buffer to copy the input data into.

I wrote a class that called calloc in its constructor, and free in its destructor. If you think this is all reasonable, you are totally wrong! Somewhere along the line this class is passed in a parameter by copy. C++ stupidly makes an implicit copy constructor. The pointer to the buffer is copied. Eventually each copy of the class is destroyed, so the destructor is called multiple times. free is called multiple times, and the program blows up.

The code fit on the screen. It took me at most 30 minutes to write, and I still totally screwed it up. I knew I should have been using std::vector. In that case I would be copying memory a zillion times, but at least it would not crash.

Tags

,

Responses


Russell O’Connor: contact me