I tested the rvalue links and moved the semantics, and I want to make sure that I understand when to copy the copy, and when it should follow the semantics of movement.
Given the following
class NRVCA { public: NRVCA(int x): {} NRVCA(const NRVCA & Rhs) {} NRVCA& operator=(const NRVCA& dref) {} }; NVCRA GetATemp() { return NVCRA(5); } NVCRA GetACopy() { NVCRA ret(5); ... return ret; } int main() {
In this case, the semantics of movement does not play any role, and the only difference from C ++ 03 in C ++ 11 is that instead of having the compiler resolved, they had to be eliminated.
So, Question 1. In what cases do I guarantee that the copy constructor will or will not be canceled.
Question 2. Is there a way to force the compiler not to be eliminated.
Question 3. Is there a logical reason why I would not want the compiler to do this, assuming that you have logically sequential copy operations.
Question 4. If I define a move constructor, the movement will occur in cases where the copy will not be moved anyway. Should this affect my class design.
c ++ c ++ 11
rerun Feb 13 2018-12-12T00: 00Z
source share