Overloaded Member Functions

In Hour 5, you learned how to implement function polymorphism, or function overloading, by writing two or more functions with the same name but with different parameters. Class member functions can also be overloaded.

The Rectangle class, demonstrated in Listing 13.1, has two DrawShape() functions. One, which takes no parameters, draws the Rectangle based on the class's current values. The other takes two values, a width and a length, and draws the Rectangle based on those values, ignoring the current class values.

Listing 13.1. An Illustration of Overloading Member Functions
 0: //Listing 13.1 Overloading class member functions 1: #include <iostream> 2: 3: // Rectangle class declaration 4: class Rectangle 5: { 6: ...

Get Sams Teach Yourself C++ in 24 Hours, Third 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.