C++ | Implementing a Stack using STL deque and Adapter design -


getting ready exam , passed upon question cannot confidently answer. need implement stack using stl deque , adapter design, of following right approach: (there can 1 answer)

1. template <typename t> class stack: public deque<t> {}; 2. template <typename t> class stack {private: deque<t>* dptr; }; 3. template <typename t> class stack {protected: deque<t>* dptr; }; 4. template <typename t> class stack {private: deque<t> {};} 5. template <typename t> class stack: private deque<t> {}; 6. template <typename t> class stack {protected: deque<t> d; }; 

any tips solution appreciated. thanks.

you never want publicly inherit stl container. they're not designed because "pay go" reasons have no virtual destructor. other forms of inheritance creating unnamed members won't serve purpose in case (they can useful using c apis etc). rules out 1 , 5. can have either private or protected member. choose protected because leave options open other classes inheriting you. leaves 3 , 6. want value or pointer. stl container can happily manage own resources when destructed, unlike raw pointer. 6 clear winner.


Comments