Suppose I have 3 classes: Base
, Derived
and Chunky
. Derived
is derived from Base
, and Base
has a member of type Chunky
(Chunky
is large, and I don't want to copy it unless I have to).
Here is Base
, assume that we cannot change it in any way (no, we can't create a constructor for it):
class Base
{
public:
Chunky monkey;
}
Derived
looks something like this:
class Derived : public Base
{
// option 1
Derived(Chunky const& monkey)
{
this->monkey = monkey;
}
// option 2
Derived(Chunky monkey)
{
// does this do anything useful, or am I wasting my time by calling std::move?
this->monkey = std::move(monkey);
}
}
I like option 2 better because the intent is clearer and I don't have to create a reference value, but do we still have the benefit of std::move
when monkey
can't be initialised in constructor initializer list? How would you solve this problem (again assuming Base
can't change)?
In case anyone wants to know, monkey in this case is an std::function, and this discussion didn't really answer my question.