For the title of this article, I believe many people will say yes like me two weeks ago.
Please refer to my experiences below --
Two weeks ago, an inexplicable error occurred when the program was closed.
After searching for a long time, it was found that an error occurred while deleting a pointer during exitinstance, which pointed to the cframewnd subclass,
At this time, the pointer value is 0 xdddddddd, which is destined to be an unusual address: deleted.
Why has it been deleted? The answer is in msdn --
Do not use the C ++DeleteOperator to destroy a frame window. UseCwnd: destroywindowInstead.CframewndImplementationPostncdestroyWill delete the C ++ object when the window is destroyed.
When the user closes the frame window, the defaultOncloseHandler will callDestroywindow.
Otherwise, destroywindow is called, and eventuallyPostncdestroyCalled.
The following MFC functions are implemented in the c: \ Program Files \ Microsoft Visual Studio 9.0 \ Vc \ atlmfc \ SRC \ MFC \ winfrm. cpp file.
void CFrameWnd::PostNcDestroy(){// default for frame windows is to allocate them on the heap// the default post-cleanup is to 'delete this'.// never explicitly call 'delete' on a CFrameWnd, use DestroyWindow insteaddelete this;}The red part is already quite clear. You don't need to explain it again. So the answer to the title is --
[This sentence may be true in Standard C ++, but it is not necessarily true that MFC "takes the initiative" to do a lot of work for us after it simply looks at our own code .]