Overloading the Assignment Operator
On several occasions, I told you that the object initialization and object assignment are different things in C++. When you are dealing with built-in data types, this distinction is often academic. Consider, for example, the following segment of the client code.
int v = 5; int u = v; // variable u is initialized
Compare this with the following segment of code.
int v = 5; int u; u = v; // variable u is assigned
In the first example, variable u is initialized at definition. In the second example, variable u is assigned after definition. For built-in variables, the end result is the same. When these computational objects are objects of programmer-defined types that handle their own memory, the difference ...
Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.