Skip to content

Instantly share code, notes, and snippets.

@buger
Created November 2, 2009 08:20
Show Gist options
  • Save buger/224029 to your computer and use it in GitHub Desktop.
Save buger/224029 to your computer and use it in GitHub Desktop.
class Complex
{
// DECLARE THE SPECIFIED GLOBAL FUNCTION AS A FRIEND
// OF THIS CLASS...
friend Complex operator+(double, Complex);
public:
Complex(float re, float im)
: myReal(re), myImag(im)
{}
// ETC. ETC. AS BEFORE...
};
Complex operator+(double d, Complex c2)
{
// CAN NOW ACCESS PRIVATE MEMBERS OF c2...
Complex sum(d+c2.myReal, c2.myImag);
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment