Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.

C++
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;
	}
};
Posted
Updated 24-Oct-12 15:13pm
v2
Comments
Mohibur Rashid 24-Oct-12 20:40pm    
Did you learn c++ at all? if you didn't its pointless asking these question in forum. cause in few lines this cant be explained that would make sense to you
DrBones69 24-Oct-12 21:08pm    
Yes, but I'm a bit rusty. I've been writing in RM/COBOL for the last 17 years and this OOP stuff is a bit tricky. I'm trying to understand the Document/View architecture. This is just a piece of the puzzle I'm trying to put together.
chaau 24-Oct-12 21:19pm    
Looks like trolling to me.
DrBones69 24-Oct-12 21:23pm    
Really? Andrew Really?
Sergey Alexandrovich Kryukov 24-Oct-12 22:13pm    
Maybe, this is a joke, and I'm pretty much sure you're not trolling, but...

If I wanted to troll, I would probably chose some style like this one and enjoyed to see how experts will go out of awkward position. I don't want to get caught by this, even if this is not trolling.

Imagine something tells the joke, all are laughing, but one is asking to explain the humor. Trolling or not, but the one who catch the lure and try to explain the humor would be in awkward position. Some requests should be denied as inadequate. And I'm not afraid of making you harm, because an attempt to "explain a class" cannot help you anyway. I tried to explain why, below.
--SA

1.
C++
CContact() {}   <------- What's this?


Default constructor of CContact. It will be called when you create an instance of CContact without any parameters.
C++
CContact localInstance;// Here defaul constructor will be called.


2.
C++
void Serialize(CArchive& archive);  <--------- Function declaration? Right?


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

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


= 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.
C++
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.
 
Share this answer
 
Comments
Mohibur Rashid 24-Oct-12 22:26pm    
I will say a good effort.
for the
1. CContact(){}:replace it as the default constructor
2. void Serialize(CArchive& archive):the Serialize function is a complex function about storage the data or output the data
3. CContact& operator=(const CContact& contact):is the copy the parameter(also the object) to the object
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900