Drama over - I malloced instead. :)
Printable View
Drama over - I malloced instead. :)
That is no solution.
First, if that class is non-POD, you cannot create objects using malloc(). All malloc() does is allocate bytes, that's it. The only way to actually create an object is to either declare one, or create one dynamically using operator new.
Using malloc() is equivalent to having me dump all the parts of a car in front of you. You can't drive it, you can't open the door, but all the parts are on the floor sitting there. On the other hand, operator new (or declaring an object) is equivalent to having the car built, ready to drive, open the door etc.
Regards,
Paul McKenzie
Granted, since you are creating an array of char, malloc() will work, but it is walking a tight rope to use malloc() in C++ since you could accidentally use it for a non-POD type.Quote:
Originally Posted by richiebabes
Frankly, a far simpler and safer solution would be:
Now, you no longer need to worry about managing the memory for chpts, and if you do need a char*, just write &chpts[0].Code:std::vector<char> chpts(sPoints.GetLength() + 1);
God sakes man you would still have to free!:lol:
Stop trying to take some shortcut!
Do it for yourself.
What you really need to do is to get each pointer from your shapes and call delete on them after you are done with them
but before you remove them from your CArray.
Ok you have all sorts of good advice. Now try to take it. Short of VNCing your desktop there is alot of good stuff here. Now empower yourself, and do it!