RAD Studio
ContentsIndex
PreviousUpNext
Overloading The Assignment operator =

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

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:

X& X::operator = (const X& source)
{
   // memberwise assignment
}
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!