-1

I am new to C++ and am trying to understand overloading to get my arithmetic operators to overload successfully. Here is the code that doesn't compile.

ComplexNumber ComplexNumber::operator*(const ComplexNumber& rightOp) const
{
double newValue = realNumberValue * rightOp.realNumberValue;
return ComplexNumber(newValue);
}
DEnumber50
  • 219
  • 2
  • 4
  • 19

3 Answers3

2
return ComplexNumber(newValue);

There is no constructor of ComplexNumber which accepts only one argument.

Venkatesh
  • 1,529
  • 14
  • 28
0

You don't have any constructor that take one value(double) as a parameter
Add this to your implementation file

ComplexNumber::ComplexNumber(double val)
{
double complexNumberValue = val;
double realNumberValue = 0;
}

This will fix the issue but you have to figure out yourself what to do for the logic part

Ahmed
  • 2,096
  • 4
  • 25
  • 40
0

You only have a two argument constructor, but you are trying to invoke a single argument constructor.

b4hand
  • 9,115
  • 4
  • 44
  • 49