Is there really a βdeleteβ element in the array without creating a new one? Am I making a hole in an array of some kind?
In C ++, if you have an array:
Foo array[10];
Then all 10 elements will be built by default. In general, there is no concept of array elements that are used and βdeletedβ. One way to track this idea is to make the actual values ββin the elements of the array optional, for example:
boost::optional<Foo> array[10];
You can read the optional<> library acceleration library at http://www.boost.org/doc/libs/release/libs/optional/
To document alternatives, I'll talk about the disgusting. You can call the destructor on one of the elements: array[3].~Foo(); This is very dangerous, because when the array itself goes out of scope, the destructor for each element will be called, and a prerequisite for this is to create a properly constructed object, so you must be sure to create Foo again in this element (using "placement" new ). There is nothing in the array itself that will help you keep track of which elements your destructors caused by you to call - you will need to track this yourself (some records about this inside the objects will probably work in practice, but access to the object after destruction - this behavior is undefined). You need to be very careful that in all code paths, including due to exceptions, you track instantly unused array elements. You really do not want to do this.
If you want to remove an element from an array to save memory, use smart pointers:
shared_ptr<Foo> array[10];
Then you can independently manage individual elements of the array, while only the elements that are still filled are destroyed when the element goes beyond the bounds. Suitable smart pointers are available in boost or C ++ 11, or you can use std::auto_ptr<> , but you should carefully read about your semantics in advance to find out if this is suitable and how to use it safely.
Separately, if there is Foo::operator=(Some_Type*) , then you can set array[3] = NULL; , and he will do everything that the assignment operator did in array[3] . However, if Foo not a pointer, it is probably a bad idea to let someone assign it NULL .