Declaring Overloaded Member Functions in a Class

The idea of overloading is to use the same name for more than one function in a class.

This can be useful when you have separate names for functions that do essentially the same thing, but differ only in the number or types of arguments required. For instance, anExternalInterface has member functions DisplayText(), DisplayRequest(), and DisplayNumber(). Wouldn't it be nice to be able to just call a function named Display() and have the compiler figure out which implementation to call based on the arguments provided?

C++ makes this fairly simple.

For instance, to the compiler, the following declarations represent separate and distinguishable member functions of anExternalInterface, despite having ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND 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.