Synthetic copy constructors and copy constructors initializing __ functions

Source: Internet
Author: User
Copyconstructor.cpp:Defines the entry point for the console application.

#include "stdafx.h"

class A
{public
:
	A () {}
	~a () {}
	int v;
};

Class B
{public
:
	B () {}
	
	//b (b &b): A (B.A) {}	//copy constructor for the composite copy constructor I
	
	//b (b &b) c16/>//{
	//	a = B.A;			Copy constructors corresponding to synthetic copy constructors II
	//}
	
	~b () {}
	
	A;
};

int _tmain (int argc, _tchar* argv[])
{
	b b;
	B.A.V = 1;
	B B0 = b;//Invoke composite copy constructor return
	0;
}

Note:

//1. The composite copy constructor is the default copy constructor.

//2. The composite copy constructor is equivalent to an assignment to all member variables.

//3. Therefore, if a member's default assignment operation does not satisfy the requirement (if a linked list or contains pointers),
it is necessary to define the overloaded assignment operator for the member class to make the composite copy constructor work.

//4. Generally, for the underlying class, it is best to implement constructors, copy constructors, destructors,
and (note) overloaded assignment operators.

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.