I am a rookie of C++ and I am looking at how to improve the efficiency of my code using move constructor and move assignment. But I have a few questions not clear about the move semantics:
1.Do I have to declare move constructor and assignment myself? I see a lot of conditions on when a move constructor will be implicitly declared, but assume I declare the following
SomeClass(SomeClass && other) = default
Should I get a usable move constructor implicitly?
2.What does the implicitly declared move constructor do? Does it simply call the move constructor of its member classes one by one? And I assume the copy action is always performed for primitive types such as int.
3.Instead of moving instance variables one by one, why does not C++ simply move the class as a whole? For example, if I have a class
SomeClass {
private:
Class1 member1;
Class2 member2;
Class2 member3;
}
then does C++ move Class1, Class2, Class3 one by one? It sounds a lot simpler if C++ move SomeClass pointer as a whole.