About the mechanism of copy constructor

For example, I want to copy the contents of object A for object B.

Then the process should be the copy constructor Mr. into a temporary object (such as C), then C is assigned to B, and finally delete C.

But if the A inside the member that is a pointer, even if we can custom make the pointer of A and B in the point in different position, so that in the A, B was deleted when free space is not associated with each other. But the C pointer and B should be the same.?

Furthermore, when deleted in C the temporary object, the system is how to ensure the pointer in B not out of control.?

Started by Clement at November 14, 2016 - 8:53 AM

Why should a C out? Constructing B is operating in B

Posted by Christopher at November 17, 2016 - 9:27 AM

Look deep copy and shallow copy of it; but in practical use, try not to use the object copy.

Posted by Teresa at November 23, 2016 - 9:50 AM

LZ, This problem is about the deep and shallow copies of the problem. .

As a consequence, the repeated release.

If not to copy to save resources so shallow, can consider to use reference counting. .

Posted by Primo at November 25, 2016 - 10:01 AM

The system cannot guarantee
So a pointer when do not use the default copy constructor member, but to write a written in private. or

As mentioned above, this is the deep and shallow copies of

Posted by Guy at December 05, 2016 - 10:04 AM


Detailed comparison, said

Posted by Sunny at December 18, 2016 - 10:40 AM

The principle, the DOS command, assembly language, C language computer (not including C++), code writing, data structure, compiler, operating system, computer network, database principle, regular expressions, other languages (including C++), architecture...

To learn the programming advice:
Eye hand over a thousand times better!
Books to read than a thousand hand knock!
Hand knock thousands of lines as single line!
The Dan Buyuan code thousand lines as single step corresponding assembly line!

Examples of "single step type structure" or "copy" or "as a function parameter" or "as the function return value return" or "in operation" or "out of scope" statement assembly code corresponding to a few steps, would come to the class of "constructor" or "copy constructor" or "operator overloading" or "destructor" corresponding to the C/C++ source code.

When debugging VC according to Alt+8, Alt+7, Alt+6 and Alt+5, open the window, the window assembly stack, memory window and register window at each sentence corresponds to C assembly, single step and observe the corresponding stack, memory and register change, so again not what all understand it.
For VC, after the so-called 'debugging' is connected to the compiler through, press F10 or F11 key step a step at a time later, or in a line according to the F9 set breakpoints by F5 execution time stopped at the breakpoint.
(Turbo C or Borland C Turbo Debugger debugging, Linux or Unix using GDB test, see every sentence corresponds to C assembly and step through the observation of the corresponding memory and register changes. )

Posted by Alston at December 31, 2016 - 10:51 AM

++

Posted by Bing at January 01, 2017 - 11:03 AM


Direct copy.

Posted by Atwood at January 03, 2017 - 11:29 AM

+++
First understand the copy constructor, copy constructor is to copy an object to a new object, that is used to initialize, generating a temporary object does not exist the problem

Posted by Chris at January 09, 2017 - 12:26 PM