friend operator problem.

hello folks of the C++ forum :)

I'm having some trouble understanding the concept of a friend operator.
*without* placing friend before an operator declaration, I shoudln't be able to acces the private members. However, this eems to work just fine:

1
2
3
4
5
6
    voorraad2& operator+=(const voorraad2& x)
    {
        small += x.small;
        big += x.big;
        return *this;
    }


It accesses the private members, even changes them...
How is this possible?

Thanks!
If it's a member operator is like any other member function. If it's not, it must be friend to access private and protected members
But how can I make the operator NOT a member function?
By making it global:

1
2
3
4
5
6
7
8
9
class MyClass
{
};

// this is global, and therefore not a member function:
MyClass operator + (const MyClass l, const MyClass r)
{
  // ...
}
Hmm ok, thanks guys!
Topic archived. No new replies allowed.