Re: delete this; return ret;
Chandra Shekhar Kumar wrote:
> > My confusion is that the
> > object should have been destructed at
> > that time.
> u have not called delete on the pointer myGame yet,
Yes, he had.
gameOver does the delete on myGame through
It is completely irrelevant what you call the variable
which holds the address of an object.
When you execute a new you get the address of an object.
You then pass that very same address to delete and the
object is wiped of the memory. What you do with that
address, where you store it, how you call the variables
that hold that address is completely irrelevant.
You get an address from new and you have to pass that
address to delete. That's all that matters.
> so the object is
no it is not.
The object is already destroyed.
> if u change yr main like this:
> int main()
> Game myGame;
> int score = myGame.gameOver();
> then u will get BUS error....coz there is no object in this case....
There is an object even in this case. But it has not
been allocated with new. Thus you can't use delete to
get rid of it.
Karl Heinz Buchegger
|All times are GMT. The time now is 08:39 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.