O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, fifth edition by Rogers Cadenhead, 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

Hour 15. Using Operator Overloading

Operator Overloading

The built-in types in C++ work with operators such as addition (+) and multiplication (*), making it easy to use these types in expressions:

int x = 17, y = 12, z;z = x * (y + 5);

The C++ compiler knows to multiply and add integers when the * and + operators appear in an expression. The preceding code adds 5 to y, and then multiplies the result by x. The z integer is assigned the value 289.

A class could provide the same functionality with multiply() and add() member functions, but the ...

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