"C + + Primer" study in the 13th chapter, about Mobile operations:
1#include <string>2 3 classFoo {4 Public:5Foo (intAintB, std::stringC=""): X (a), Y (b), S (NewSTD::string(c)) {}6Foo (Constfoo&) =default;7foo&operator=(ConstFoo &) =default;8Foo (foo&&) noexcept=default;9foo&operator= (Foo &&) noexcept=default;Ten~Foo () {} One A intx = the; - inty = A; -STD::string*s; the }; - intMain () - { -Foo V ( -, A,"s"); + int*p = &(v.x); - int*P2 = &(V.Y); + A Foo v2 (Std::move (v)); at int*PP = &(v2.x); - int*PP2 = &(V2.Y); - return 0; -}
The results of the operation are as follows:
Have the following questions:
- How does a move constructor operate on a built-in type? The result of the run is displayed as a copy of the class value (the int value is the same, the address differs). The book does not elaborate, only the compiler to move the built-in type, the book's examples are in the move constructor deliberately value initialized the current object. So it seems that the move constructor simply copies the built-in type, and the code in the book is initialized with extra time?
- The move constructor "steals" the resources of the class type, consistent with the conclusion of the book, for the mobile operation.
A question about the move operation