Quote from C ++ Primer
if we explicitly ask the compiler to generate a move operation using = default, and the compiler cannot move all members, the move operation will be defined as remote
a move constructor is defined as remote if the class has a member that defines its own copy constructor but does not define a move constructor , or if the class has a member that does not define its own copy constructor and for which the compiler cannot synthesize the move
Some code seems to violate this rule:
#include <utility>
#include <iostream>
struct X {
X() = default;
X(const X&) { std::cout << "X(const X&)" << std::endl; }
int i;
};
struct hasX {
hasX() = default;
hasX(const hasX &) = delete;
hasX(hasX &&) = default;
X mem;
};
int main()
{
hasX hx, hx2 = std::move(hx);
}
X the move constructor does not define, and the compiler cannot synthesize it for it.
, hasX .
, hasX , hx2 = std::move(hx) "X(const X&)", hasX, X . , , .
, ++ ?
, : VS2015 -
!