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.

Making operator<< virtual?

I need to use a virtual << operator. However, when I try to write: virtual friend ostream & operator&…

c++ operators operator-overloading virtual
Function template with an operator

In C++, can you have a templated operator on a class? Like so: class MyClass { public: template<class T&…

c++ templates operator-overloading
What is "Best Practice" For Comparing Two Instances of a Reference Type?

I came across this recently, up until now I have been happily overriding the equality operator (==) and/or Equals method …

c# .net comparison operator-overloading equality
What operators should be declared as friends?

In some books and often around the internet I see recommendations like "operator== should be declared as friend". How should …

c++ operator-overloading
A positive lambda: '+[]{}' - What sorcery is this?

In Stack Overflow question Redefining lambdas not allowed in C++11, why?, a small program was given that does not compile: …

c++ c++11 lambda operator-overloading language-lawyer
Why overloaded operators cannot be defined as static members of a class?

C++ syntax allows defining overloaded operators either inside the struct/class like: struct X { void operator+(X); } or outside of …

c++ operator-overloading static-methods
How do I overload an operator for an enumeration in C#?

I have an enumerated type that I would like to define the >, <, >=, and <= operators for. I …

c# enums operators operator-overloading
C++ friend function can't access private members

This is supposed to be a string class with a bunch of operators and functions, including two friend functions. And …

c++ operator-overloading friend
Operator Overloading in C++ as int + obj

I have following class:- class myclass { size_t st; myclass(size_t pst) { st=pst; } operator int() { return (int)…

c++ operators operator-overloading operator-keyword
Arithmetic operator overloading for a generic class in C#

Given a generic class definition like public class ConstrainedNumber<T> : IEquatable<ConstrainedNumber<T>>, IEquatable&…

c# generics operator-overloading math primitive-types