class Super
{
public:
A();
virtual ~A();
};
class SubB;
class SubA: public Super
{
public:
SubA();
SubA(const SubA& s);
SubA(const SubB& s);
~SubA();
};
class SubB : public Super
{
public:
SubB();
SubB(const SubA& s);
SubB(const SubB& s);
~SubB();
};
//in later code using these classes
Super* s1 = new SubA();
Super* s2 = new SubB(*s1);
const Super& SubA::operator=(const SubA& s);
const Super& SubA::operator=(const SubB& s);
//although this would be transparent from the outside
const Super& SubA::operator=(const Super* s){
SubA* a;
if(a = dynamic_cast<SubA*>(s))
*this = *a;
else{
SubB* b;
b = dynamic_cast<SubB*>(s);
*this = *b;
}
}