O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

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

Overloading

Operator overloading is a special kind of polymorphism that adds new functionality to existing operators for inherited classes. Recall from the discussion of inheritance that operators are not inherited. Because of this, you need to specify behavior for operators to work with the data associated with the new class.

You have not yet read about operators in classes, so now is a good time for a little refresher on operators in general. Essentially, a class definition can include definitions for all the mathematical and logical operators.

These operators can then be overloaded as if they were functions. This enables you to define a class that contains an overloaded assignment operator, which would assign one set of data to the other, ...

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