O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required