Skip to Main Content
Sams Teach Yourself C++ in 24 Hours, fifth edition
book

Sams Teach Yourself C++ in 24 Hours, fifth edition

by Jesse Liberty, Rogers Cadenhead
April 2011
Beginner content levelBeginner
464 pages
9h 18m
English
Sams
Content preview from Sams Teach Yourself C++ in 24 Hours, fifth edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Sams Teach Yourself C++ in 24 Hours, Sixth Edition

Sams Teach Yourself C++ in 24 Hours, Sixth Edition

Rogers Cadenhead, Jesse Liberty

Publisher Resources

ISBN: 9780672331855Purchase book