Inheritance between Index and Index1 Class
Understand operator overloading in the base class, Index, and derived class, Index1.
We'll cover the following...
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.
Access this course and 1400+ top-rated courses and projects.