I can not deal with the interfaces and their implementation. Please explain how to implement them correctly and how it is at least approximately done in my case. Literally, the task looks like this You have the following interface:

template<class T> class Stack { public: Stack(); ~Stack(); Stack( const Stack& ); Stack& operator=( const Stack& ); size_t Count() const; void Push( const T& ); T Рор(); // throws an exception if stack is empty private: //..... }; 

Please write the following: How to be done.

  • It is very important not to confuse the concept of an interface as an abstract class and an interface as a list of open class methods. These completely different concepts are called the same. And the funny thing is that those and those have a realization =). For example, the fact that in the description of your tag, it is most likely not what you need. - mrFieldy
  • @mrFieldy, where does the abstract class come from? The abstract class provides an interface for its derivatives, so it can be called an interface class. And what of it? ... Interface concept is independent - AR Hovsepyan
  • @ARHovsepyan description of the tag "interface" look. This is not at all what the author of the question needs, right? - mrFieldy
  • @mrFieldy, I'm talking about your comment, and not about how well the author of the question put it - AR Hovsepyan

1 answer 1

You are told that most likely you have two options - to inherit from this class and implement all its functions (but this is unlikely - there is no virtual destructor and the section is privately left, which intrefesov should not have).

Therefore, most likely, you just need to write the implementation of functions.

 template<class T> class Stack { public: Stack(); ~Stack(); Stack( const Stack& ); Stack& operator=( const Stack& ); size_t Count() const; void Push( const T& item); T Рор(); // throws an exception if stack is empty private: std::vector<T> m_data; }; 

further implementation itself

 size_t Stack::Count() const { return m_data.size(); } void Stack::Push( const T& item) { m_data.push_back(item); } 

and so on...

  • only Pop () removes the element and usually returns bool or returns nothing, and to get a tail element you need to define T & top () and const T & top () const - AR Hovsepyan
  • one
    This is a question for who came up with the interface. - KoVadim
  • I just added it from myself for the author of the interface - AR Hovsepyan
  • From the author has not yet received a single message, clarification. - nick_n_a