Why can friend operators be public or private?
EDIT: If I had more space for the thread title, it should've been entitled:
"Why doesn't it matter if friend operators are public or private?"
I know the friend keyword gives a class or function access to a classes private data, but i'm confused about how they behave with it's calling class.
I mean, if a function/operator/class is in the private section, I shouldn't be allowed to access it outside the class right?
Given the following example:
Code:
class Test{
public:
friend bool operator==( const Test& lhs, const Test& rhs ){
return lhs.data == rhs.data;
};
friend bool operator!=( const Test& lhs, const Test& rhs ){
return lhs.data != rhs.data;
};
public:
Test( int d ) : data( d ) {};
private:
int data;
};
int main(){
Test a( 1 );
Test b( 2 );
if( a != b ){
std::cout << "A and B are NOT equal.\n";
}
return 0;
}
It makes no difference whether or not the overloaded operators are in the public or private sections.
1) Is that true? Or is there more testing that can prove otherwise?
2) If it doesn't make a difference, why doesn't it make a difference?
Thanks in advance