I l@ve RuBoard Previous Section Next Section

Item 14. Writing Exception-Safe Code桺art 7

Difficulty: 5

Only a slight variant梠f course, operator=() is still very nifty.

Imagine that the /*????*/ comment in StackImpl stood for public. Implement all the member functions of the following version of Stack, which is to be implemented in terms of StackImpl by using a StackImpl member object.



template <class T> 


class Stack


{


public:


  Stack(size_t size=0);


  ~Stack();


  Stack(const Stack&);


  Stack& operator=(const Stack&);


  size_t Count() const;


  void   Push(const T&);


  T&     Top();   // if empty, throws exception


  void   Pop();   // if empty, throws exception


private:


  StackImpl<T> impl_;  // private implementation


};


Don't forget exception safety.

    I l@ve RuBoard Previous Section Next Section