I'm having an issue overriding an operator= overload. When I try to use the operator to copy one Derived object into another, it's completely avoiding the Derived override, and just calling the Base operator= :
class Base
{
public:
virtual Base* clone() const;
protected:
virtual void operator=(const Base& copyBase);
}
class Derived : public Base
{
public:
Derived* clone() const;
private:
void operator=(const Base& copyBase) override;
}
Derived* Derived::clone() const
{
Derived* clone = new (std::nothrow) Derived();
if(clone)
{
*clone = *this; // <--- Base operator= get's called
}
return clone;
}
Derived::clone() is being correctly called, but instead of calling Derived::operator= it's jumping to Base::operator=, and I can't seem to figure out why. Is there something special about virtual operator= or am I doing something silly?