May 2012
Intermediate to advanced
679 pages
16h 56m
English
Consider that we have two objects of class Point, pt1 and pt2. If data members of pt1 are initialized to some values and if we say pt2 = pt1 then data members of pt2 will have the same value as that of pt1. It means object pt2 is copied into object pt1 (Implicit overloading of = operator by the compiler). It is also possible to write a friend function to this effect. Program 7.9 illustrates how to do it explicitly.
Problem: Write a program to overload assignment (=) operator.
Solution: We cannot have implicit and explicit overloading simultaneously. Hence, we will first demonstrate explicit overloading. See Program 7.9.
Read now
Unlock full access