1

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 Answers1

0

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

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".

Community
  • 1
  • 1
kazanaki
  • 7,988
  • 8
  • 52
  • 79