The operator << is a binary operator so that means that it takes 2 and only 2 parameters.
ostream &operator
<< (ostream &strm) const
{
return strm <<
"a" << (obj.width*obj.height) << "window"
<< endl;
}
We could do this but it would not work that way we expect it since with that function, the Windows goes on the left side and the ostream goes on the right side. Therefore, we should call it like this:
my_window << cout;
Instead of this:
cout << my_window;
Making it a free function, not as a member of the class is the only way to solve this. We may give it public access to that data or we may need to make it a friend it if accesses sensitive data.