Is there any way of creating a function that accepts any version of a given template class?
e.g. this works:
ostream& operator << (ostream &out,const Vector<int>& vec);
but this doesn't:
ostream& operator << (ostream &out,const Vector& vec);
Is it possible to get the second line to work somehow for any version of vector?
e.g. vector<int>
and vector<double>
without having to write 2 separate functions?
Added to question:
I've made op<< a template function like you've suggested. In order to make it a friend function of the vector class I tried adding the following to the Vector class definition, but it didn't work:
friend ostream& operator << (ostream &out, const Vector<T>& vec);
any ideas what can be done to fix it?