Top "Operator-overloading" questions

Operator overloading is a feature of a programming language that allows custom implementations for operators depending on the types of the operands involved.

What are the basic rules and idioms for operator overloading?

Note: The answers were given in a specific order, but since many users sort answers according to votes, rather than …

c++ operators operator-overloading c++-faq
How to properly overload the << operator for an ostream?

I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did …

c++ namespaces operator-overloading iostream ostream
How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers

One of my pet hates of C-derived languages (as a mathematician) is that (-1) % 8 // comes out as -1, and not 7 …

c++ c c++11 operator-overloading modulo
Operator overloading in Java

Please can you tell me if it is possible to overload operators in Java? If it is used anywhere in …

java operator-overloading
How to overload __init__ method based on argument type?

Let's say I have a class that has a member called data which is a list. I want to be …

python constructor operator-overloading
Why doesn't Java offer operator overloading?

Coming from C++ to Java, the obvious unanswered question is why didn't Java include operator overloading? Isn't Complex a, b, …

java operator-overloading
How do I overload the [] operator in C#

I would like to add an operator to a class. I currently have a GetValue() method that I would like …

c# operator-overloading indexer
Should operator<< be implemented as a friend or as a member function?

That's basically the question, is there a "right" way to implement operator<< ? Reading this I can see that …

c++ operator-overloading
How do I overload the square-bracket operator in C#?

DataGridView, for example, lets you do this: DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5]; but for the life of me I can't …

c# collections operators operator-overloading
How to override the [] operator in Python?

What is the name of the method to override the [] operator (subscript notation) for a class in Python?

python operator-overloading