Cosider the following code:
class Foo
{
Monster* monsters[6];
Foo()
{
for (int i = 0; i < 6; i++)
{
monsters[i] = new Monster();
}
}
virtual ~Foo();
}
What is the correct destructor?
this:
Foo::~Foo()
{
delete [] monsters;
}
or this:
Foo::~Foo()
{
for (int i = 0; i < 6; i++)
{
delete monsters[i];
}
}
I currently have the uppermost constructor and everything is working okey, but of course I cannot see if it happens to be leaking...
Personally, I think the second version is much more logical considering what I am doing. Anyway, what is the "proper" way to do this?