I know that << operator can be overloaded as method function as well. The problem comes when i am using template arguments.
I've realised that i need to specify the class and as such i wrote < A > before operator<< .
Where should i write < A > if i want to use the object< < ostream syntax ?
#include <iostream>
#include <malloc.h>
using namespace std;
class A
{
private:
int x;
public :
A(int i = 0)
{
x = i;
}
A operator + (A temp)
{
return x + temp.x;
}
template <class T>
ostream & operator << (ostream &);
};
template <class T>
ostream& A::operator<<(ostream &o)
{
o<<x;
return o;
}
int main()
{
A a(33),b(-21);
(a+b).operator<<<A>(cout);
//a+b<<cout; ????
}