CS 340 - 2/25/13 // queue.cpp #include "queue.h" #include Exam on Thursday 2/28/13 ==================== return-by-reference - never return a local variable by reference MyString& MyString::operator= (const MyString &rhs) { ... return *this; } ---------- MyString s1, s2, s3; s1 = s2; // s1 is this; s2 is rhs // the above code does not use the return value s1 = (s2 = s3); The above code is implemented by the following MyString* temp = s2.operator=(s3); s1.operator=(&temp); If operator= returned by value instead of by reference MyString MyString::operator=(const MyString& rhs) s1 = (s2 = s3); The above code is implemented by the following MyString temp1 (s2.operator=(s3)); s1.operator=(temp1); ============== MyString s1, s3, s5; MyString *s2, *s4; s2 = new MyString(); // instance is on the heap s4 = &s5; // refers to an instance on // on the stack (*s2) = s3; // (*s2).operator=(s3); // s2->operator=(s3); // deep copy s1 = (*s2); // s1.operator=(*s2); s2 = &s3; // assign an address // shallow copy // we CAN write the following MyString Queue::operator= (const Point &rhs) { ... return *this; }