Yes,thank you very much for reply but I do not understand when i change the array which elements would it have because later in the program i must add some functions for example addition of two arrays if they have same length or function that eliminate duplicates form array least to greatest.
class Vector {
private:Point *vector; //is this your array?
int dim;}
if so then if you want your class to store different types like ints, doubles, floats... then you can use templates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
template<typename T>
class Vector
{
private:
T *vector; //can now hold any type
int dim;
public:
}
int main()
{
///usage
Vector<Point> my_point_container;///can hold points
Vector<int> my_int_container; /// can hold ints
}
Yes,array is vector.If i want now for example to sum two objects that are class Vector if their array length is the same how i would do that because I am confused that array type is another class
Point *vector.I know how to sum if for example array vector is int.
i assume by sum you mean joining the two arraysinternal to the Vector such that if V is a vector of size SZ and V1 is a Vector of size SZ1, where SZ==SZ1 then you can do this:
class Vector{ int *vector;
int dim;//dimension of array
Vector Add((const Vector &p)
};
Vector Vector::Add(const Vector &p) //here i do not check the length of vectors
{
int i, j;
Vector newvector(this->dim + p.dim);
for (i = 0; i < this->dim; i++)
newvector.vector[i] = this->vector[i];
for (j = 0; j < p.dim; j++)
newvector.vector[j + i] = p.vector[j];
return newvector;
}
When i call function on objects
c=a.Add(b)