C++11 move constructor

前端 未结 4 1950
清酒与你
清酒与你 2020-12-08 01:14


What would be the correct way to implement a move constructor considering the following class:

class C {
public:
    C();
    C(C&& c);
private         


        
4条回答
  •  生来不讨喜
    2020-12-08 02:04

    There is no need to implement a move constructor here since you don't have to manually manage memory. Move constructors are only useful when you manually use dynamic arrays in your class.

    You can still explicitly have the compiler create the default move constructor even though it should have already been done even if you don't request it:

    C(C&& c) = default;
    

提交回复
热议问题