Hi!
I'm trying to overload << operator and running into an error that says function template partial specialization is not allowed. I really don't understand what is partial specialization and also where exactly have I gone wrong in my code.
template < typename T > class A ; // declare the class (template)
// declare the function (template)
template < typename T > std::ostream& operator<< ( std::ostream&, const A<T>& ) ;
template<class T> class A
{
// declare the friend as a template
friend std::ostream& operator<< <> ( std::ostream&, const A<T>& obj ) ;
// ...
};
// define the the function (template)
template < typename T > std::ostream& operator<< ( std::ostream& stm, const A<T>& a )
{
// stm << ...
return stm ;
}
Tried with a forward declaration and still ran into errors. Then tried defining the friend function within the class itself and that's working. However one thing I cannot understand is if I define the function in any of these ways: