A question about the move operation

Source: Internet
Author: User

"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:

    1. 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?
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.