Writing a derived class from a given base class

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;
Wow, this free homework-writing service we provide is really getting popular, isn't it!
Finished! Do I get a prize?!
Step 1. Give up our time to do people's homework for free.

Step 2. ?

Step 3. PROFIT!!!

It's genius, I tell you...
Topic archived. No new replies allowed.