13.1.2. The Copy-Assignment Operator
Just as a class controls how objects of that class are initialized, it also controls how objects of its class are assigned:
Sales_data trans, accum;trans = accum; // uses the Sales_data copy-assignment operator
As with the copy constructor, the compiler synthesizes a copy-assignment operator if the class does not define its own.
Introducing Overloaded Assignment
Before we look at the synthesized assignment operator, we need to know a bit about overloaded operators, which we cover in detail in Chapter 14.
Overloaded operators are functions that have the name operator
followed by the symbol for the operator ...
Get C++ Primer, Fifth Edition 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.