Il suffit d'ajouter pour chacune des classes un destructeur du type :
class ClassName
{
public:
....
~ClassName()
{
std::cout << "Destruction: ClassName@" << this << std::endl
}
};
Ce qui nous donne les classes suivantes :
class ForwardCounter: public BaseCounter
{
public:
void increment()
{
if(counter < max)
counter = counter + 1;
else
counter = 0;
}
ForwardCounter(): BaseCounter() {}
ForwardCounter(const ForwardCounter& aCounter): BaseCounter(aCounter) {}
explicit ForwardCounter(unsigned theMaxValue): ForwardCounter(0, theMaxValue) {}
ForwardCounter(unsigned theCounter, unsigned theMaxValue): BaseCounter(theCounter, theMaxValue) {}
~ForwardCounter()
{
std::cout << "Destruction: ForwardCounter@" << this << std::endl
}
};
class BackwardCounter: public BaseCounter
{
public:
void decrement()
{
if(counter > 0)
counter = counter -1;
else
counter = max;
}
BackwardCounter(): BaseCounter() {}
BackwardCounter(const BackwardCounter& aCounter): BaseCounter(aCounter) {}
explicit BackwardCounter(unsigned theMaxValue): BackwardCounter(0, theMaxValue) {}
BackwardCounter(unsigned theCounter, unsigned theMaxValue): BaseCounter(theCounter, theMaxValue) {}
~BackwardCounter()
{
std::cout << "Destruction: BackwardCounter@" << this << std::endl
}
};
class BiDiCounter: public BaseCounter
{
public:
void increment()
{
if(counter < max)
counter = counter + 1;
else
counter = 0;
}
void decrement()
{
if(counter > 0)
counter = counter -1;
else
counter = max;
}
BiDiCounter(): BaseCounter() {}
BiDiCounter(const BiDiCounter& aCounter): BaseCounter(aCounter) {}
explicit BiDiCounter(unsigned theMaxValue): ForwardCounter(0, theMaxValue) {}
BiDiCounter(unsigned theCounter, unsigned theMaxValue): BaseCounter(theCounter, theMaxValue) {}
~BiDiCounter()
{
std::cout << "Destruction: BiDiCounter @" << this << std::endl
}
};