Complex Class Query

Learn a different way to overload the “+” operator.

We'll cover the following

Problem

In the program in “Complex Class with a + Operator”, how can the conversion from double to Complex be prevented, and why would we want to prevent it?

Sample run

If we try to put a Complex class object and a double value around the + operator, we want the compiler to flag it as a compilation error.

Coding solution

Here is a solution to the problem above.

Note: You would see an error while executing this code.

Get hands-on with 1400+ tech skills courses.