本文介绍了有人请解释这堂课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释该类,这是Mona的Jonathan Wood的视频"How Do I ...".我对代码不太清楚的地方做了一些评论.这是主应用程序头文件.我试图了解文档/视图体系结构,以及它们如何结合在一起.

Please explain this class, this is from MSDNs "How Do I..." video by Jonathan Wood. I made a couple of comments where the code isn''t quite clear to me. This is the main app header file. I''m trying to understand the Document/View architecture, how it all comes together.

class CContact : public CObject
{
public:
    DECLARE_SERIAL(CContact)

    CContact() {}   <------- What's this?

    CString m_sName;
    CString m_sAddress;
    CString m_sPhone;
    CString m_sEmail;
    CString m_sCity;
    CString m_sState;
    CString m_sZip;

    void Serialize(CArchive& archive);  <--------- Function declaration? Right?

    CContact& operator=(const CContact& contact) <--- What does the rest of this do?
	{
	    m_sName = contact.m_sName;
	    m_sAddress = contact.m_sAddress;
	    m_sPhone = contact.m_sPhone;
	    m_sEmail = contact.m_sEmail;
            m_sCity = contact.m_sCity;
            m_sState = contact.m_sState;
            m_sZip = contact.m_sZip;
	    return *this;
	}
};

推荐答案

CContact() {}   <------- What's this?



CContact的默认构造函数.创建不带任何参数的CContact实例时将调用它.



Default constructor of CContact. It will be called when you create an instance of CContact without any parameters.

CContact localInstance;// Here defaul constructor will be called.



2.



2.

void Serialize(CArchive& archive);  <--------- Function declaration? Right?



是的. Serialize()的定义可以在该类的cpp文件中.

3.



Yes. Definition of Serialize() may be in cpp file of the class.

3.

CContact& operator=(const CContact& contact) <--- What does the rest of this do?



=运算符CContact重载.当一个CContact实例分配给另一个CContact实例时,将调用此方法.如果未创建相同的编译器,则编译器将创建默认的= operator实现.但是在某些情况下,我们必须创建自己的= operator实现.如果有任何成员指向存储位置的指针,则我们必须为新的CContact实例准备单独的指针副本.



= operator overloaded of CContact. This will be called when a CContact instance assigned to another CContact instance. Compiler will create a default =operator implementation, if we are not created the same. But we have to create our own =operator implementation in certain situations. If any member is pointer to a memory location, then we have to prepare separate copy of the pointer for the new instance of CContact.

CContact contactA;
 //Assign member values to contactA. 
 ....
 ....

    CContact contactB; // Another CContact is created, Default constructor will be called.

// Here copying contactA to contactB, Here =operator will be called.
    contactB = contactA; // Here =operator will be called.



这篇关于有人请解释这堂课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:13