Why does a move constructor require a default constructor for its members?

前端 未结 3 1986
悲哀的现实
悲哀的现实 2020-12-16 13:03

I was trying to implement a move constructor for a class without a copy constructor. I got an error that the default constructor for a member of the class was missing.

3条回答
  •  北海茫月
    2020-12-16 13:30

    Use the constructor's initializer list to initialize the A member. As written, the move constructor uses, as the compiler says, the default constructor for A.

    B(B&& b) : a(std::move(b.a)) {}
    

提交回复
热议问题