Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: delete this; return ret; (http://www.velocityreviews.com/forums/t267695-re-delete-this-return-ret.html)

Karl Heinz Buchegger 06-25-2003 08:58 AM

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
delete this

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
> alive.


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
kbuchegg@gascad.at


All times are GMT. The time now is 06:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57