The class Test {
Public:
Static int count;
Public:
The Test ()=default;
The Test (int s);
The Test (const Test& Test)=delete;
The Test (Test& & Test).
Test& Operator=(const Test& Test)=delete;
Test& Operator=(Test& & Test).
To Test ();
Private:
Int size;
Int * PTR.
};
The Test: Test (int s) {
Size=s;
PTR=new int [s].
count++;
}
The Test: Test (Test& & Test) : the PTR (test. PTR), size (test. The size) {
Cout & lt; <"Move the copy constructor is called \ n";
}
Test& The Test: : operator=(Test& & Test) {
If (this==& amp; Test) {
return *this;
}
If (PTR! Nullptr)={
The delete [] PTR.
PTR=nullptr;
}
Size=test. The size;
PTR=test. PTR;
Test. The PTR=nullptr;
return *this;
}
The Test: : ~ Test () {
The delete [] PTR.
}
Int Test: : count=0;
VectorVec.
Void func_test (vector& & Other) {
//vectorVec.
Vec. Push_back (STD: : move (other [0]));
}
Int main (int arg c, const char * argv []) {
//insert code here...
STD: : listL={,1,421.2, 2-2,53,4,1234,14,11345,12,43,1.1};
VectorVec.
VectorVec1;
Vec1. Push_back (move (Test (1)));
Func_test (move (vec1));
//auto ans=quick_sort (l);
return 0;
}
When the func_test ginseng to const vector
CodePudding user response:
This is the perfect forwardVoid push_back (const _Ty & amp; _Val) {//insert element at the end, dojo.provide strong guarantee
Emplace_back (_Val);
}
Void push_back (_Ty & amp; & _Val) {//insert by moving into element at the end, dojo.provide strong guarantee
Emplace_back (_STD move (_Val));
}
CodePudding user response: