I need to implement the following class :
template <class Element, class Compare = std::equal_to<Element>>
class UniqueArray {
Element* data;
unsigned int size;
unsigned int max_size;
public:
explicit UniqueArray(unsigned int size);
UniqueArray(const UniqueArray& other);
~UniqueArray();
UniqueArray& operator=(const UniqueArray&) = delete;
unsigned int insert(const Element& element);
bool getIndex(const Element& element, unsigned int& index) const;
const Element* operator[] (const Element& element) const;
bool remove(const Element& element);
unsigned int getCount() const;
unsigned int getSize() const;
};
The problem is I can't assume that Element
has a defualt constructor.
Assuming I can't see the implementation of Element
class meaning that there might be other constructors but I don't know how much parameters there are and what are their types.
How can I initialize the data attribute of UniqueArray
?
For example Element can be a Point which has a constuctor with two arguments(and no defualt constructor) But the point is I don't know which element is being sent and I don't know what constructor this Element has. The code supposed to be generic.