Just implement a specialized version of your Vector
for the type Person
class Person
{
};
template <typename T>
class Vector{
friend ostream& operator<<(ostream& os, const Vector<T> &rop);
};
template<>
class Vector<Person>
{
friend ostream& operator<<(ostream& os, const Vector<Person> &rop);
};
If you have other methods in Vector<T>
which you don't want to have in Vector<Person>
, just leave them out in the specialization.
Running example
Edit: To answer the question in the comment: Yes there is a different way, just define the operator outside of your class like this:
template <typename T>
class Vector{
};
template<typename T>
std::ostream& operator<<(std::ostream &os, Vector<T> &prop)
{
return os;
}
template<>
std::ostream& operator<<(std::ostream &os, Vector<Test> &prop)
{
return os;
}
And specialize a version for the Vector<Person>
type.