I\'m pretty new to C++, and am trying to come to grips with virtual assignment. The program below consists of an abstract base class with two data members, and a derived cla
This is a bit old, but in case anyone else stumbles upon it:
To add to Mark's answer, you can do this by implementing
Derived & operator=(const Abstract & rs);
In this case you may need to use rs
by casting it: dynamic_cast
Of course this should only be done carefully.
The full implementation would be:
Derived & Derived::operator=(const Abstract & hs)
{
if (this == &hs)
return *this;
Abstract::operator=(hs);
style = new char[std::strlen(dynamic_cast(hs).style) + 1];
std::strcpy(style, dynamic_cast(hs).style);
return *this;
}