Re: delete this; return ret;

Discussion in 'C++' started by Karl Heinz Buchegger, Jun 25, 2003.

  1. 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
    Karl Heinz Buchegger, Jun 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Heinz Buchegger

    Re: delete this; return ret;

    Karl Heinz Buchegger, Jun 24, 2003, in forum: C++
    Replies:
    0
    Views:
    831
    Karl Heinz Buchegger
    Jun 24, 2003
  2. Unforgiven

    Re: delete this; return ret;

    Unforgiven, Jun 24, 2003, in forum: C++
    Replies:
    0
    Views:
    770
    Unforgiven
    Jun 24, 2003
  3. priyanka
    Replies:
    34
    Views:
    797
    Malcolm
    Jun 4, 2006
  4. metal
    Replies:
    8
    Views:
    493
    Bruno Desthuilliers
    Oct 30, 2009
  5. X X
    Replies:
    4
    Views:
    341
    red floyd
    Jul 19, 2010
Loading...

Share This Page