jeudi 26 mars 2020

Calling order of base move assignment operator

What is the correct place to call base class move assignment operator from the derived class, as the first statement or the last statement, before return statement?

Class Base {
public:
    Base &operator=(Base &&o) {
        // move all the members here
        return *this;
    }
};

class Derived {

public:
    Derived &operator=(Derived &&o) {
      // Is this correct? Base class move here or below?
      Base::operator(std::move(o));  

      // move all the members here

      // should I have base class move call here? Base::operator(std::move(o));  
      return *this;
    }
};

Aucun commentaire:

Enregistrer un commentaire