I'm trying to figure out why I cannot call the overloaded operator << as member function just as I call the operator+ as member function.
#include "pch.h"
#include <iostream>
using namespace std;
class A
{
int x;
public: A(int i = 0) { x = i; }
A operator+(const A& a) { return x + a.x; }
template <class T> ostream& operator<<(ostream&);
};
template <class T>
ostream& A::operator<<(ostream& o) { o << x; return o; }
int main()
{
A a1(33), a2(-21);
a1.operator+(a2);
a1.operator<<(cout); // Error here
return 0;
}