I have a weird problem with a copy creator. I'm sure that is something stupid but I can't understand why is working in that way. Lets say that I have a Class Vector that stores the length of the vector and its data, and another class that inherits from it that has a member of Vector class (in the example code I have renamed the templated vector to RVec = Vector<double>)
template <typename T>
class Vector{
/* friend std::ostream& operator<<(std::ostream& output, Vector &v);*/
public:
Vector(){}; // General creator
Vector(int nin); // Creator of a vector of size n with zeros
Vector(const Vector<T> &v); // Copy constructor
~Vector(){};
void Show();
private:
int n;
T* x;
};
typedef Vector<double> RVec ;
class SEM{
public:
SEM(){};
SEM(int N); // Creator
~SEM(){};
void Show();
private:
RVec r;
};
In the creator of the second class I have to define a temporary copy and then assign to the member r of the SEM class. I'm sure that there is a more elegant way of doing but I don't know how to do it. Any tips?