CProgrammer, the answer to your question is no. You must delete an allocation the same way you new it.
swiftcoder is wrong. His example does not work. If you allocate an array like this:
Object *objs = new Object[someint];
You must delete it like this:
delete [] objs;
You cannot do this:
for ( int i = 0; i < someint; i++ ) { delete &objs; }or for ( int i = 0; i < someint; i++ ) { objs.FunctionThatContainsDeleteThis(); }
If you want to delete indvidual objects in an array, you need an array of pointers like this:
Object * apObjs[ someint ]; for ( int i = 0; i < someint; i++ ) { apObjs = new Object; }
Then you can/must delete the objects like this:
for ( int i = 0; i < someint; i++ ) { delete apObjs; }or for ( int i = 0; i < someint; i++ ) { apObjs->FunctionThatContainsDeleteThis(); }
Other than that, delete this is a bad idea if you can't guarantee that the object was allocated with new, and not new[] or on the stack or as a member variable.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!