C++ Programming Topic
Using the following Counter class as your Base class, explain (and show)
how inheritance works by deriving a BetterCounter class
from it that adds the prefix and postfix forms of the decrement (- -) operator,
making it possible to execute statements such as
BetterCounter bctr1, bctr2, bctr3;
bctr2 = bctr1++;
bctr3 = - - bctr2;
.
.
.
---------------------------------------------------------------------------------------------------------------------
class Counter
{
private:
int count;
public:
Counter (int c = 0)
{ count = c; }
void setCount ( int);
int getCount ( );
Counter operator++ (int);
Counter operator++ ( );
};
void Counter::setCount (int c)
{ count = c; }
int Counter::getCount ( )
{ return count; }
Counter Counter::operator ++ ( )
{
count++;
Counter temp (count);
return temp;
}
Counter Counter::operator ++ (int)
{
Counter temp (count);
count++;
return temp;