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.

Defining operator< for a struct

I sometimes use small structs as keys in maps, and so I have to define an operator< for them. …

c++ operator-overloading
Why override operator()?

In the Boost Signals library, they are overloading the () operator. Is this a convention in C++? For callbacks, etc.? I …

c++ boost operator-overloading functor function-call-operator
__lt__ instead of __cmp__

Python 2.x has two ways to overload comparison operators, __cmp__ or the "rich comparison operators" such as __lt__. The rich …

python operator-overloading
error: overloaded 'operator<<' must be a binary operator (has 3 parameters)

I know there are plenty of questions like these, but I couldn't find a solution that worked for me. I …

c++ operator-overloading overloading
Using the less than comparison operator for strings

I'm following a tutorial for C++ and looking at strings and overloading with operators such as +=, ==, != etc. Currently I have …

c++ operator-overloading string-comparison stdstring
C++: overloading ++ for both pre and post increment

Can we overload operator++ for pre-increment and post-increment? i.e. calling SampleObject++ and ++SampleObject results correctly. class CSample { public: int …

c++ operator-overloading
How to overload unary minus operator in C++?

I'm implementing vector class and I need to get an opposite of some vector. Is it possible to define this …

c++ operator-overloading
Operator[][] overload

Is it possible to overload [] operator twice? To allow, something like this: function[3][3](like in a two dimensional array). If …

c++ operator-overloading
Can I use ' == ' to compare two vectors. I tried it and seems to be working fine. But I don't know whether it will work in more complex situations

First example: int main(){ using namespace std; vector<int> v1{10, 20, 30, 40, 50}; vector<int> v2{10, 20, 30, 40, 50}; if(v1==v2) …

c++ vector operator-overloading equality
c++ friend function - operator overloading istream >>

My question is in regards to friend functions as well as overloading the << and >>. From my …

c++ operator-overloading friend operator-keyword