I am practically done with this project but got stumped in one area
I am trying to use operator overloading and multiplying 2 to the complex number.
Since I used operator* already, how do I call the operator with 2* complex no?
How do I write the code for it? Just one tiny issue. Others are compiling fine.
Linda1
-6
Newbie Poster
Recommended Answers
Jump to PostHi,
Why dont use friend function for overloading *
Syntaxfriend complex0 operator*(int, complex0&); friend complex0 operator*(complex0&, int);
Jump to Post//overload operator*
it is similar to overloading << and >>
Just give declaration inside complex0 class as friend.friend complex0 operator* (int no, complex0& com);
complex0 operator* (int no, complex0& com) { complex0 temp; temp.realPart = no*com.realPart; temp.imaginaryPart = no*com.imaginaryPart; return temp; }
All 5 Replies
selvaganapathy
31
Posting Pro
Linda1
-6
Newbie Poster
selvaganapathy
31
Posting Pro
Linda1
-6
Newbie Poster
Linda1
-6
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.