Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #ifndef Set_hpp
  2. #define Set_hpp
  3.  
  4. template <class T>
  5. class MultiSet{
  6. public:
  7.     MultiSet(){};
  8.     virtual void add(T param){};
  9.     bool test(T param){};
  10.     virtual void remove (T param){};
  11. };
  12.  
  13. template <class T>
  14. class Set : public MultiSet<T>
  15. {
  16. public:
  17.     Set(){};
  18.     void add(T t);
  19.     void remove (T t);
  20. };
  21.  
  22. template <class T>
  23. class duplicateException{
  24. public:
  25.     T value;
  26.     duplicateException(T v){value = v;};
  27. };
  28.  
  29. template <class T>
  30. class removeException{
  31. public:
  32.     T value;
  33.     removeException(T v){value = v;};
  34. };
  35.  
  36.  
  37. template <class T> void Set<T>::add(T t){
  38.     if (this->test(t))
  39.         throw new duplicateException<T>(t);
  40.     else
  41.         MultiSet<T>::add(t);
  42. }
  43.  
  44. template <class T> void Set<T>::remove(T t){
  45.     if (!this->test(t))
  46.         throw new removeException<T>(t);
  47.     else
  48.         MultiSet<T>::remove(t);
  49.  
  50. }
  51.  
  52. #endif // Set_hpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement