Correct use of `= delete` for methods in classes

后端 未结 2 1595
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 08:42

Is the following snipplet correct for un-defining all otherwise generated methods and constructors for a class?

struct Picture {

  // \'explicit\': no accidenta         


        
2条回答
  •  盖世英雄少女心
    2021-01-31 09:35

    Seems fine to me. The return value of operator= must be a normal reference, even if the object is constructed from a rvalue reference. That is because you can't just compile an lvalue (*this) to an rvalue.
    And it should take that rvalue reference per non-const Picture& operator=(Picture&&). How would you move from a constant object? ;)

提交回复
热议问题