Discover copy assignment operator, include the articles, news, trends, analysis and practical advice about copy assignment operator on alibabacloud.com
C ++ copy constructor, copy assignment operator, mobile constructor, mobile assignment operator, destructor, right value reference, reference qualifier instance, right value of Constructor13.1 copy, assign value, and destroy 13.1.1 copy
Copy constructor If the first parameter of a constructor is a reference to its own class type, and any additional arguments have default values, this constructor is a copy constructor. Copy constructor The first argument must be a reference type.
C ++-copy constructor, copy-assignment operator, destructor, assignmentoperator
For a class, copy constructor, copy-assignment operator, move constructor, move-assignment operator, and destructor are collectively referred to as copy control.
Let's
For a class, we refer to copy constructor, copy-assignment operator, move constructor, move-assignment operator, destructor collectively as copy ControlToday we first talk about the copy constructor, copy-assignment operator destructor these
Assignment operator
The assignment symbol "=" is the assignment operator, which is to assign a data to a variable. The function of "a=3" is to perform an assignment operation (or assignment operation). Assign the constant 3 to variable a. You can
First, make it clear:
The system has provided the default copy constructor and the = copy operator. That is, the so-called shallow copy.
But sometimes we have to provide our own rewrite. Generally, it is rewritten with pointers.
For a simple example,
First, make it clear:
The system has provided the default copy constructor and the = copy operator. That is, the so-called shallow copy.
But sometimes we have to provide our own rewrite. Generally, it is rewritten with pointers.
For a simple example,
Note: classes that contain dynamically assigned members should provide copy constructors and overload the "=" value assignment operator.
The following examples will be used:
Class cexample {public: cexample () {pbuffer = NULL; nsize = 0 ;}~ Cexample
In C + +, there are three major functions of copy control (copy constructor, assignment operator, destructor), and in C++11, move constructor is added to move assignment operator. I would venture to name them six functions.First, the constructor
In C + +, there are three major functions of copy control (copy constructor, assignment operator, destructor), and in C++11, move constructor is added to move assignment operator. I would venture to name them six functions.First, the constructor
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.