how to handle delete by illegal address

Posted by Davit Siradeghyan on Stack Overflow See other posts from Stack Overflow or by Davit Siradeghyan
Published on 2010-04-30T18:04:45Z Indexed on 2010/04/30 18:07 UTC
Read the original article Hit count: 506

Suppose we have a situation like this. How to handle this problem? How to protect code from crashes? I know about and use boost smart pointers. But what to do if we have this situation.

struct Test
{
    int a;
    int b;
    int c;
};

Test global;

int main()
{
    Test *p = new Test;

    p->a = 1;
    p->b = 2;
    p->c = 3;

    p = &global;

    delete p;

    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about exception-handling