There is tree of classes rooted at CBase (single-inheritance). CSub is derived from CBase, and other classes derived from CBase or CSub, and CBase having virtual member functions.
All classes must be assignable. Some classes have members (pointers) that need special treatment in assignment (pointers). How do I ensure assignability within this tree of classes ?
First, I thought I need to make "operator=" virtual. Then I realized it's wrong. Then is this at all possible:
CBase *x = new CSub;
CBase *y = new CSub;
*x = *y; // is this okay ?
If not, how do I assign *y to *x without evil downcast ? I have many questions here.
If I need to cast every time I assign through CBase*, then this does not look typesafe, does it ? Do I need to insert type checks in "operator=" to check that lhs and rhs have same type ? etc etc. Examples are welcome.
Thanks Viki