// A1_9.cpp #include using namespace std; class Y { public: Y& operator=(const Y &y) { if(this==&y) return *this; cout << "\n assigning a Y object"; return *this; } }; class B { public: B& operator=(const B &b) { if(this==&b) return *this; cout << "\n assigning a B object"; return *this; } }; class C : public B { Y y; public: C& operator=(const C &c) { if(this==&c) return *this; cout << "\n assigning a C object"; *(static_cast(this)) = c; //// alternate syntax /////////////////////////////////////////////////////// // ((B&)*this) = c; // always works, using old cast // B::operator=(c); // works only if B defines operator=(...) ///////////////////////////////////////////////////////////////////////////// y = c.y; return *this; } }; void main() { C c1, c2; c1 = c2; cout << "\n\n"; }