2017-09-27 9 views
0

저는 C++ Primer 5 판을 읽고 다음과 같은 문제점을 가지고 있습니다. 이 책은 합성 이동 조작이 h 제된 것으로 정의 된 몇 가지 경우를 나열합니다. 그 중 하나는 "복사 생성자와 달리 이동 생성자는 클래스에 자체 복사 생성자를 정의하지만 이동 생성자를 정의하지 않는 멤버가 있거나 클래스가 정의하지 않은 멤버를 갖는 경우 삭제 된 것으로 정의됩니다 자신의 복사 작업 및 컴파일러가 이동 생성자를 합성 할 수없는 경우 이동 할당에 대해서도 마찬가지입니다. " 또한 다음과 같은 데모 코드를 제공합니다 : 모두 GCC 7.2.1를 들어,합성 이동 생성자의 동작

// assume Y is a class that defines its own copy constructor but not a move constructor 
struct hasY { 
    hasY() = default; 
    hasY(hasY&&) = default; 
    Y mem; // hasY will have a deleted move constructor 
}; 
hasY hy, hy2 = std::move(hy); // error: move constructor is deleted 

그러나 및 연타-900.0.37를, 코드가 실행 가능한 것입니다,이 책은 잘못?

#include <iostream> 

struct Y { 
    Y() { std::cout << "Y()" << std::endl; } 
    Y(const Y&) { std::cout << "Y(const Y&)" << std::endl; } 
    //Y(Y&&) { cout << "Y(Y&&)" << endl; } 
}; 

// assume Y is a class that defines its own copy constructor but not a move constructor 
struct hasY { 
    hasY() = default; 
    hasY(hasY&&) = default; 
    Y mem; // hasY will have a deleted move constructor 
}; 

int main() { 
    hasY hy, hy2 = std::move(hy); // error: move constructor is deleted 
    return 0; 
} 

답변