CWnd and std::vector

  • Anonymous - 2011-01-04

    I've tried to store some CWnd class in a std::vector.
    But, it just create the window that the class destructor is call and exit the application.
    Can I store CWnd class in a std::vector?
    If not, how may I store it?
    Thanks a lot,
    Best regards

  • David

    David - 2011-01-05

    Yes you can store a CWnd in a vector. Just be aware that when the vector goes out of scope, the CWnd's destructor will get called (also destroying the CWnd's window) which is presumably the problem you're having. To avoid this you could make the vector a member variable of some other class or (shudder) a global variable.

    You might prefer to put a CWnd pointer into the vector. Putting a CWnd smart pointer (based on Shared_Ptr, not auto_ptr) would be even better. Smart pointer are automatically deleted when they go out of scope.

    Best regards,

  • Anonymous - 2011-01-05



Log in to post a comment.