friend operator function

Hi all,
1
2
3
4
5
6
7
8
9
10
class Cents { 
    private:     
        int m_nCents; 

    public:     
        Cents( int nCents ) : m_nCents( nCents ) {}
        friend bool operator > ( Cents& c1, Cents& c2 ) {
            return c1.m_nCents > c2.m_nCents;     
        } 
};

Why is the operator overload function a friend function, and not just a normal function?
because you declared it a friend function using the friend keyword.
yeah, I know :) but why is it made a friend? a normal function would do great, I think.
I don't really see the need to make it a friend.

Aceix.
OK. It was in a tutorial, so I thought it had a special advantage to make it friend.
I this case the operator > has access to the private and protected members of class cents. This doesn't make sense here because you would do just fine to overload the > operator in class cents and it would serve the same purpose.
Topic archived. No new replies allowed.