Inheritance between Index and Index1 Class

Understand operator overloading in the base class, Index, and derived class, Index1.

Challenge

Write a program that has an Index class in it that keeps a count and gets incremented when ++ is done on an Index object. Derive from it an Index1 class that provides the overloaded decrementation, --, operator.

Sample run

Here’s what you should see when you run the program.

Current value of count = 0
Current value of count = 1
Current value of count = 2
Current value of count = 1

Coding exercise

Your job is to define an overloaded ++ operator in the Index base class and an overloaded -- operator in the Index1 derived class. Try to solve this challenge on your own. If you can’t solve it, you can look at the solution and explanation below.

Get hands-on with 1400+ tech skills courses.