Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: delete this; return ret;

Reply
Thread Tools

Re: delete this; return ret;

 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      06-25-2003


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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"return delete (new int)" compile but "return delete (new X X C++ 4 07-19-2010 05:47 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM
Help: Delete a single carriage return in a file, but not a double carriage return? Steve Anderson Perl Misc 3 06-21-2004 12:48 AM
Cannot Delete, (The Delete Key Won't Work) Lee Something Computer Support 13 10-15-2003 09:51 PM



Advertisments