OOPortal
J2EEOnline RationalDB
prev prev
Course navigation
Operator overloading guidelines
Any time a class uses new to construct objects, it should provide an explicitly overloaded assignment operator. This advice is analogous to our rule that such a class provide an explicit copy constructor.
The compiler-provided default assignment operator semantics would, in most cases, give spurious behavior. This leads to a suggested normal form for classes with heap-managed memory. This normal form rule applies as well to reference counted classes. The reason the assignment operator returns a reference is to allow assignment to work efficiently. This requires lvalue semantics.
Course navigation