non-member operator function

My question is: how can we make an operator function, which is not a member of a class, access private data members of class or do manipulations on objects of class? and why do we use such operator function?
You can make it friend
1
2
// anywhere in your class body:
friend ret_type operator op ( param_1, param_2 );


You need to have external operator when the first argument of it is not an object of the class
But it means that the friend function has to be declared 'inside' the class at least... Can't I declare and define it 'outside' the class, in main body?
No, that's because only the implementor of the class can decide which functions can access private members
( otherwise it wouldn't make sense to have them private )
Topic archived. No new replies allowed.