Re: How to know the pointer of a object is deleted or not?

Discussion in 'C++' started by Robert Bauck Hamar, Jul 2, 2003.

  1. * flekso:
    | "yangyong" <> wrote in message
    | news:bdtrsj$7k8$...
    |> class A
    |> {...};
    |>
    |> int GetSome( const A* ptr)
    |> {
    |> // Is ptr valid??? How to know??
    |> }
    |
    | if you have control over class design maybe you could implement your custom
    | new operator to add each instance of a class to some shared memory table:
    |
    | active[pointers];
    |
    | and something similar with delete.

    This could work, until someone does:
    A myA;
    GetSome(&myA);

    A better idea would be to add the instance in the constructor, and
    remove it in the destructor. As a bonus, it will work with derived
    classes.

    --
    Robert Bauck Hamar
     
    Robert Bauck Hamar, Jul 2, 2003
    #1
    1. Advertising

  2. Robert Bauck Hamar

    flekso Guest

    i stand corrected

    "Robert Bauck Hamar" <> wrote in message
    news:...
    > * flekso:
    > | "yangyong" <> wrote in message
    > | news:bdtrsj$7k8$...
    > |> class A
    > |> {...};
    > |>
    > |> int GetSome( const A* ptr)
    > |> {
    > |> // Is ptr valid??? How to know??
    > |> }
    > |
    > | if you have control over class design maybe you could implement your

    custom
    > | new operator to add each instance of a class to some shared memory

    table:
    > |
    > | active[pointers];
    > |
    > | and something similar with delete.
    >
    > This could work, until someone does:
    > A myA;
    > GetSome(&myA);
    >
    > A better idea would be to add the instance in the constructor, and
    > remove it in the destructor. As a bonus, it will work with derived
    > classes.
    >
    > --
    > Robert Bauck Hamar
    >
     
    flekso, Jul 2, 2003
    #2
    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. Ron Natalie
    Replies:
    25
    Views:
    665
    flekso
    Jul 8, 2003
  2. B. Penn
    Replies:
    6
    Views:
    631
    Old Wolf
    Aug 9, 2004
  3. opistobranchia
    Replies:
    1
    Views:
    351
    Larry I Smith
    Aug 14, 2005
  4. Chumley the Walrus
    Replies:
    2
    Views:
    277
    Tom Gosselin
    Aug 10, 2004
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    282
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page