Created
November 2, 2009 08:20
-
-
Save buger/224029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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