11 The Fraction Class

Some people talk about object orientation as though it were easy: You wave the magic wand of C++ and your troubles disappear. But writing a useful class requires thought and planning. To be reusable—to offer so much that other programmers will make use of it—requires that you place serious functionality into the class.

But the good news is that once you develop, write, and test a class that truly meets your needs, you’ve created a strong addition to the C++ language. Alternatively, you can use classes and objects as a way to package code and data together.

Because the task of writing a real class is involved, I’m going to focus mainly on a single class over the next several chapters: the Fraction class, which (when done) ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart 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.