Ok I know the difference between delete and delete[] BUT this question just all of a sudden popped in my head since "NOTHING" happens when I use delete[] for all purposes.
Now I know when to use one or the other but it still for some odd reason bothers me that delete[] on anything is acceptable in g++/codeblocks.
Example:
struct Foo
{
int* X;
int NumberOfElements;
//.......
};
int main()
{
Foo* F = new Foo; //Create ONE instance of Foo.
delete[] Foo; //Does NOTHING fishy. It just deletes foo?
//OR
delete Foo; //Does the same as the above no? If yes, why bother ever using delete?
Foo* FA = new Foo[10]; //Create 10 instances of Foo.
delete[] Foo; //Deletes all instances of Foo pointed to by FA.
//But not..
delete Foo; //Big problem/leaks?
}
Why is it safe to use delete[] without getting a crash or something?
I was doing:
template<typename T>
void DeleteAll(T* &Type, size_t Size)
{
if (Size > 1)
delete[] Type;
else
delete Type;
Type = NULL;
}
and thinking about whether or not I even have to specify the size to use the correct delete since delete[] is no different?