One day, I wrote a simple Stack class:
I compiled it and then use it in some project...Code:class LinkedList { public: int value; LinkedList *next; LinkedList() : next(0) { } }; class Stack { protected: LinkedList *top; public: Stack() : top(0) { } void push( int value ); int pop(); };
3 years later, I need a stack that counts every item that pushed or popped into it
I lost the Stack source code and the only thing left is its header and compiled binary
due to OOP matter, I just extend it then.
the next year , I need a stack that throws an Exception when it's emptyCode:class CountingStack : public Stack { protected: int count; public: CountingStack() : count(0) { } void push( int value ) { //count++ } int pop() { //count-- } int getCount(); };
but it doesn't need to count every item that pushed or popped into it
So I wrote this ExceptionStack
And now, I need both CountingStack and ExceptionStack featuresCode:class ExceptionStack : public Stack { public: int pop() { //throw Exception if the stack is empty ( top == NULL ) } };
but again, I lost their source code!
Because of the project's time limit, I couln't rewrite the Stack code.
So, I guess I need to write this kind of class, but I found a problem...
Code:class CountingExceptionStack : public CountingStack, public ExceptionStack { public: void push( int value ) { CountingStack::push( value ); } /* int pop() { What should I write here?? } */ };



LinkBack URL
About LinkBacks



CornedBee