I posted earlier today about template classes, but was pretty far off and got a solution to my previous problem from here. Of course when that's dealt with, there's always a new one that I can't seem to figure out.
Given the following constructor:
template <typename Type, int inSize>
sortedVector<Type, inSize>::sortedVector():
size(inSize), vector(new Type[inSize]), amountElements(0)
{}
I want to make a dynamic array, which I then can insert elements of whatever type into via an add-method. The calls from main will look as follows:
sortedVector<Polygon, 10> polygons;
sortedVector<int, 6> ints;
How can I initialize the array to zero when it's constructed? I can not set an object to zero ;)
I thought I was being smart and tried to overload the =-operator for Polygon and given an int it would do nothing. Turns out I can not do that ):
Any good suggestions?
Also, here's the template class sortedVector:
template <typename Type, int inSize>
class sortedVector
{
public:
sortedVector();
int getSize();
int getAmountElements()
bool add(const Type &element);
private:
Type *vector;
int size;
int amountElements;
};
and just in case also Polygon:
class Polygon
{
public:
Polygon();
Polygon(Vertex inVertArr[], int inAmountVertices);
~Polygon();
void add(Vertex newVer);
double area();
int minx();
int maxx();
int miny();
int maxy();
int getAmountVertices() const;
friend bool operator > (const Polygon &operand1, const Polygon &operand2);
friend bool operator < (const Polygon &operand1, const Polygon &operand2);
private:
Vertex *Poly;
int amountVertices;
};