+ 1
How to implement and link multiple template classes in C++?
How to write a code for queue and stack template classes that uses a doubly linkedlist template class as its base? Eg: inside the stack class push,pop operations happen using linkedlist.add() and linkedlist.del() classes that used the functionality given in the linkedlist template. (P.s multiple inheritance not to be used) Please tell me how to go with the program!
1 Odpowiedź
+ 3
I would use composition.
For example:
template<typename T>
class LinkedList{...};
template<typename T>
class Stack{
public:
void push( T value ){
m_linkedList.add( value );
}
private:
LinkedList<T> m_linkedList;
};
And the same for your Queue.
You could also use inheritance but I like to avoid it when I can.