Question

I'm wondering how it is possible to make use of both a copy constructor and assignment operator from a derived class. It seems that all other questions on this issue involve the base class also having an assignment operator of its own, which my base class is not allowed to have.

The member functions in question are:

SpecialOrder& operator=(const SPecialOrder &source)

Was it helpful?

Solution

You will need to handle copying the base class members one way or another.

The standard way is to call the base class assignment operator in the derived class, e.g. Order::operator=(source); (Order::Order(source); is incorrect, in fact your compiler should have told you as much, you cannot call a constructor on an already created object).

Your other option is to use the public / protected methods of the base class to try and set the state, but if you cannot access the base class assignment operator or copy constructor, or they are not defined / deleted, it is likely the base class was never intended to be copied in the first place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top