#include <iostream>
#include <fstream>
using namespace std;
class Integer
{
public:
int i;
Integer (int ll = 0, int k = 0) : i (ll)
{
cout << "\nconstructor A\n";
}
Integer operator<< (const Integer& left, const Integer& right);
};
Integer operator<< (const Integer& left, const Integer& right)
{
cout << "\ndsfdsfdsf : " << "===" << right.i << "\n";
return left ;
}
int main ()
{
Integer l;
l << 5 << 3 << 2;
return 0;
}
This code gives the above titled error when I remove the keyword friend from the declaration of the << operator.
There isn’t anything private here, so why is it happening?
When the operator declaration does not contain
friend, the declaration declares a member, and a member has its class as its implicit first argument. With the two explicit arguments, this makes three arguments for a binary operator.