123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
#include <iostream> #include <vector> using namespace std; template <class T> class Set { public: Set(); Set(Set<T>& setObject); void add(T addedValue); T* getArray(); int getQuantity(); void increaseCapacity(); ~Set(); private: vector<T> items; int quantity; }; template <class T> Set<T>::Set() : quantity(0) { } template <class T> Set<T>::Set(Set<T>& setObject) : quantity(setObject.getQuantity()) { items.clear(); T* object = setObject.getArray(); for(int i = 0; i < quantity; i++) { items.push_back(object[i]); } } template <class T> void Set<T>::add(T addedValue) { items.push_back(addedValue); quantity = items.size(); } template <class T> T* Set<T>::getArray() { return &items[0]; } template <class T> int Set<T>::getQuantity() { return this->quantity; } template <class T> Set<T>::~Set() { if(!items.empty()) { delete [] &items; } }
delete [] &items;
delete
new
~Set()