views:

29

answers:

1

Hi friends.

I am leaning towards using std::tr1::shared_ptr to automatically manage a pointer to a utility class in my GUI program.

Basically here's a skeleton of the program:

int main () {
    Allocate dynamic memory for utility class

    GUI code.. GUI code... GUI Code..
    GUI Main Loop
}

The program finishes when the user calls a quit_cb or if SIGINT (CTRL+C) is called. In my situation, I need to be able to call delete in either case. I can call delete in quit_cb but if SIGINT is called ... then delete is never called! Is it appropriate to use a smart pointer in this case?

+1  A: 

You can catch the Ctrl-C as well and call quit_cb/delete even in that case.

http://stackoverflow.com/questions/1641182/how-can-i-catch-a-ctrl-c-event-c

So no matter the exit case you are always covered. No need for an auto-pointer or anything "smart".

kazanaki