Friend Functions

You can also declare a single function with the friend keyword, instead of an entire class. For example:

class YourClass

{

friend void YourFunction( YourClass yc );

private:

int topSecret;

};

void YourFunction( YourClass yc )

{

yc.topSecret++; // Modify private data

}

Friend functions are often used for operator overloading. See Chapter 8, “Operator Overloading and Conversion Functions,” for more information.