18.4 Warts

I l @ ve RuBoard

The fixed_pt class described in this chapter has been simplified a bit to make it easy to understand and to best teach operator overloading. There are some limitations to this code that you should be aware of, however.

First, although the number of digits after the decimal point is controlled by the constant fixed_exp , in reality the code is limited to two digits after the decimal point. That's because the input and output functions have this limit hardcoded in. (They should be made general.)

Also, with C++ templates (see Chapter 24) there is no reason to hardcode the location of the decimal point at all. You can create a general-purpose template that lets you specify the fixed point when you declare the class. More on this later.

In spite of these problems, this class does serve as a good illustration of how to perform operator overloading in C++.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net