cpp-intro icon indicating copy to clipboard operation
cpp-intro copied to clipboard

041-move-support: 「基本の実装」掲載のムーブ代入演算子は参照を返していない

Open hi-hori opened this issue 4 years ago • 0 comments

    // ムーブ
    Integer( Integer && r )
        : ptr( r.ptr )
    { r.ptr = nullptr ; }
    Integer operator =( Integer && r )
    {
        delete ptr ;
        ptr = r.ptr ;
        r.ptr = nullptr ;
        return *this ;
    }

上記のコードが掲載されていますが、上記実装だと自身のコピーを返してしまいます。 正しくは Integer & operator =( Integer && r ) ではないでしょうか?

hi-hori avatar Jul 15 '21 23:07 hi-hori