简体   繁体   中英

Compiler-generated move member functions on static data members

In Effective Modern C++, item 17 ( Understand special member function generation ), Scott Meyers said that the generated special move member functions (move constructor and move assignment operator) perform “memberwise moves” on the non-static data members of the class .

The move operations are generated only if they're needed, and if they are generated, they perform “memberwise moves” on the non-static data members of the class.

I tried to understand the non-static condition but I couldn't, can anyone explain to me why can't they perform that on static data members?

I think it simply referres to static members, as here:

struct A{
   static int s; // static member, (not moved or copied when moving/copying an instance
   int w; // non-static member
};

Because static members are not part of the created objects from that class. Though they don't need to be moved (or copied in case of copy constructor).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM