class base {
Public:
The base () : c (new int (1)), s (" x ") {
Cout & lt; <"Defaut constructed base" & lt;};
Int * c;
string s;
The base (base& & Bas) : c (bas) c) and s (bas) s) {
Bas. C=nullptr;
Cout & lt; <"Move the construct" & lt;}
The base (base& BBB) {
C=new int (* BBB. C);
S=BBB. S;
Cout & lt; <"Copy the construct" & lt;}
~ base () {
Cout & lt; <"Delete" & lt;The delete c;
Cout & lt; <"Deconstruct base" & lt;}
};
The following operation
base ba1.
Base & amp; & Ba2=STD: : move (ba1);
Base ba3 (STD: : move (ba1));
Ba2. ~ base ();
Ba1. ~ base ();
Don't complain, from print to see a total of four destructor, why? If only one ba2 or destructor ba1, can also be normal,
delete0
Deconstruct base
Delete0
Deconstruct base
Delete0x133cc20
Deconstruct base
Delete0
Deconstruct base
If according to the following operation complains double free:
base ba1.
Cout & lt;Base & amp; & Ba2=STD: : move (ba1);
Ba2. ~ base ();
I understand because ba2 and ba1 refer to the same area, so there will be a repeating mistakes, that is what mobile structure, can repeat release?
CodePudding user response:
Value type of the data, there is no need to call the destructor, the program will automatically call them, you call twice, so according to call fourYou there are only two classes, a ba1, one is via mobile tectonic ba3,
CodePudding user response: