RAD Studio |  |

Overloading The Assignment operator =
See Also
Collapse All

The assignment operator=( ) can be overloaded by declaring a nonstatic member function. For example,

Copy Code

    class String {
         .
         .
         .
       String& operator = (String& str);
         .
         .
         .
       String (String&);
       ~String();
    }

This code, with suitable definitions of String::operator =(), allows string assignments str1 = str2 in the usual sense. Unlike the other operator functions, the assignment operator function cannot be inherited by derived classes. If, for any class X, there is no user-defined operator =, the operator = is defined by default as a member-by-member assignment of the members of class X:

Copy Code

    X& X::operator = (const X& source)
    {
       // memberwise assignment
    }

See Also

Example Of Overloading Operators

Overloaded Operators And Inheritance

Overloading Binary Operators

Overloading Operator Functions

Overloading The Class Member Access Operators ->

Overloading The Function Call Operator ( )

Overloading The Subscript Operator []

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!