Constructors and destructors

Source: Internet
Author: User




This article is organized by Code Assistant software to publish content unrelated to the software more enjoyable reading, more enjoyable writing, easier publishing









SDI cognition

By simply creating SDI from the wizard, adding features and not looking into the details of SDI, now take a look at the time to learn the Ribbon interface that VS2010 comes with.

A constructor protected type

class  Public    CFrameWndEx{ protected://Only from serialization to create CMainFrame(); Declare_dyncreate(CMainFrame)

 Public    CDocument{protected://Only from serialization to create Ctttdoc(); Declare_dyncreate(ctttdoc)

TView &NBSP: public    cview  { Protected://Create only from serialization     ctttview ( ;     Declare_dyncreate ctttview" //attribute public :     ctttdoc* getdocument ( "   const ; 

Declared as a protected type, you cannot instantiate a class directly, because MS has been dynamically instantiated in the app initialization function.

By default, CMainFrame cannot be instantiated directly, but is dynamically instantiated in the app's App::initinstance () by Runtime_class

Registers the application's document template.    The document Template//will use the connection between the composition document, frame window and view csingledoctemplate* pdoctemplate; Pdoctemplate=New CSingleDocTemplate(Idr_mainframe, Runtime_class(Ctttdoc), Runtime_class(CMainFrame),//main SDI frame window Runtime_class(Ctttview));if(!pdoctemplate)return FALSE; AddDocTemplate(Pdoctemplate);

The second destructor is virtual

Implement public: Virtual ~cmainframe();

Implement public: Virtual ~ctttdoc();

Implement public: Virtual ~ctttview();

Cause: The destructor is then refactored before the parent class, because the parent pointer can point to the subclass object, such as:

void Main () { base* p =}

If the parent class is not a virtual function, the compiler will simply refactor the parent class, not the pipe class, thus causing the subclass memory to leak.

When the parent destructor is set to a virtual function, the compiler discovers that it is a virtual function, so it can be judged that the pointer is a subclass, and therefore the subclass and its parent are broken down.


Constructors and destructors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.