-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
  • 239
  • 2
  • 5
  • 19

3 Answers3

2
return ComplexNumber(newValue);

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

Venkatesh
  • 1,537
  • 15
  • 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,176
  • 5
  • 26
  • 40
0

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

b4hand
  • 9,550
  • 4
  • 44
  • 49