M
Mark
the following is an example of code that won't compile.
(I've reproduced the problem in a simplistic format )
....
#include <iostream>
using namespace std;
class MyClass
{
public:
unsigned int myint;
ostream& operator<<( ostream& o,MyClass& myclass)
{
return o;
}
};
I get : error C2804: binary 'operator <<' has too many parameters
However I can fix this if I declare it as
friend ostream& operator<<( ostream& o,MyClass& myclass)
{
return o;
}
Why? The function is doing nothing that requires access to the internals
of the class ( there are no internals !! )
(I've reproduced the problem in a simplistic format )
....
#include <iostream>
using namespace std;
class MyClass
{
public:
unsigned int myint;
ostream& operator<<( ostream& o,MyClass& myclass)
{
return o;
}
};
I get : error C2804: binary 'operator <<' has too many parameters
However I can fix this if I declare it as
friend ostream& operator<<( ostream& o,MyClass& myclass)
{
return o;
}
Why? The function is doing nothing that requires access to the internals
of the class ( there are no internals !! )