Exercises


  • Create an Int class which represents and int, and then overload the + and - operators so that you can add and subtract two Ints.
  • Make the Int class even more useful by overloading more operators of your choosing (++, --, /, *, %, etc). Be sure that if you overload divison that you truncate correctly.
  • Create an Int class with multiple versions of the + operator so that you can add an Int to another Int, a regular int, a float, etc. Support any types that come to mind, but be sure to truncate floating point types.
  • Create conversion overloaders for the Int class so that it can be converted to an int, a float, etc. Choose whatever types you like. If you get bored, find a way to convert an Int into a Taco.
  • Create a Taco class which uses this brand new Int class to store any attributes which previously were ints.
  • Create a Taco class (you can make a basic one or use one from before) and overload the + operator for it.
  • If yo've created a Taco class which supports the linked list of Tortillas in the last chapter, then overload the + operator for the Taco class, making sure that the linked lists of Tortillas are added together correctly (so that by adding two Tacos, you get a double decker Taco).


Table of Contents

Operator Overloading | Binary Operator Overloading | Unary Operator Overloading | Overloading Conversion Operators
Using Overloaded Operators | Exercises | Continuing the Journey