complex-numbers: operator overloading
See original GitHub issueThe complex-number exercise testsuite and example use methods add
, mul
etc. instead of the operators __add__
, __mul__
. Using the latter, one could do ComplexNumber(1, 2) + ComplexNumber(3, 4)
instead of ComplexNumber(1, 2).add(ComplexNumber(3, 4))
which might be a more natural/pythonic way to write these. Perhaps changing it to the operator version would make this exercise a bit more interesting and applicable to “real life” use cases?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
C++ Program to Subtract Complex Number Using Operator ...
Example: Binary Operator Overloading to Subtract Complex Number ... In this program, three objects of type Complex are created and user is asked...
Read more >Operator overloading Complex numbers
a basically arithmetic type for which operator overloading makes sense. – complex added as explicit type in 1999 C standard.
Read more >Operator Overloading in C++ - GeeksforGeeks
So the main idea behind “Operator overloading” is to use c++ operators with class variables or class objects. Redefining the meaning of ...
Read more >Add/Subtract Complex Numbers using Operator Overloading ...
If we define complex numbers as objects, we can easily use arithmetic operators such as additional (+) and subtraction (-) on complex numbers...
Read more >C++ program to overload addition operator to add two ...
Overload the + operator and take another complex number c2 as argument · define a complex number called ret whose real and imag...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
__abs__()
can also be overridden.@SaschaMann, good point, thanks! I totally agreed.
It* will showcase use of Python`s magic methods an operator overloading (Java for example does not have such luxury) in action. Perhaps it would be a good idea to include a hint explaining what it is in the exercise as well