2

I'm new to move semantics, and I've been reading several resources that explain the correct way of defining a move constructor and assignment operator. All introductory material seems to use a class with a pointer member variable as examples. However I don't understand what to do with reference data members and class data members. For example:

Class A
{
(...)
private:
   ClassB& reference_member;
   ClassC object_member;
}

What should a move constructor and move assignment operator do, supposing that ClassB and ClassC are non-trivial classes (with several member variables that are too expensive to copy). I want to be able to move instances of A around effectively.

  • 3
    For `ClassC` you just move it, and rely on the fact that tha class itself has proper move-constructor and/or move-assignement. As for the reference, it's not data that your class owns, so how to deal with that depends on your use-case. – super Apr 11 '21 at 08:01
  • That's strange you didn't find anything about this, I think this [answer](https://stackoverflow.com/a/34486446/7143595) and [cppreference](https://en.cppreference.com/w/cpp/language/move_constructor) contain the tips you need – MatG Apr 11 '21 at 09:16

0 Answers0