P
Pranav Shah
I want to Overload operator "+" such that I can add two complex numbers
and but the sum into a third one, but I only want to call the
constructor 3 times.
Here is the current algorithm:
Declare Three complex objects:
Complex a,b,c;
Sum a and b and save the result in c:
c = a + b;
The current function that I have to do this looks something like:
return( new Complex(a.Real + b.Real, a.Imaginary + b.Imaginary);
Because of this the constructor is called 4 times.
3 times when the objects are defined in the main program and once more
when the Operator overloading is called.
How can I cut this down to 3 Constructor calls? I know I am supposed to
use pointers, but I do not know the right syntax.
Any help will be great. Thanks.
and but the sum into a third one, but I only want to call the
constructor 3 times.
Here is the current algorithm:
Declare Three complex objects:
Complex a,b,c;
Sum a and b and save the result in c:
c = a + b;
The current function that I have to do this looks something like:
return( new Complex(a.Real + b.Real, a.Imaginary + b.Imaginary);
Because of this the constructor is called 4 times.
3 times when the objects are defined in the main program and once more
when the Operator overloading is called.
How can I cut this down to 3 Constructor calls? I know I am supposed to
use pointers, but I do not know the right syntax.
Any help will be great. Thanks.