December 2013
Beginner
656 pages
16h 42m
English
EXPLORATION 32
![]()
Assignment and Initialization
The final step needed to complete this stage of the rational type is to write assignment operators and to improve the constructors. It turns out C++ does some work for you, but you often want to fine-tune that work. Let’s find out how.
Assignment Operator
Until now, all the rational operators have been free functions. The assignment operator is different. The C++ standard requires that it be a member function. One way to write this function is shown in Listing 32-1.
Listing 32-1. First Version of the Assignment Operator
struct rational{ rational(int num, int den) : numerator{num}, denominator{den} ...
Read now
Unlock full access