bl**********@gmail.com wrote:
I current have
template<typename T>
class Vector
{
...
Vector(const Vector& Vin)
{
...
}
..
}
int main(void)
{
Vector<double> V(5);
Vector<int> V1(V);//doesnt work
}
How would I solve this problem?
Take a look at constructing from a range of iterators.
The std::vector does it, so could your Vector. Essentially,
you need to define a constructor that would take two arguments,
and construct your vector (sorry, Vector) from them. Make that
constructor a member template:
template<typename T>
class Vector
{
...
template<typename Iterator> Vector(Iterator i1, Iterator i2)
{
storage = ???[std::distance(i1, i2)];
while (i1 != i2)
*storage++ = *it1++;
}
...
I know that it's not necessarily how you implemented your class
(ahem, template), but it should give you the idea.
V