Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Allows you to redefine how standard operators (like +, -, <<) work with your custom classes.
class Complex {
public:
double r, i;
Complex operator + (const Complex &obj) {
return {r + obj.r, i + obj.i};
}
};
Complex c3 = c1 + c2; // Calls the + operatorMakes user-defined types behave like built-in primitive types.
You cannot create NEW operators or change the precedence of existing ones.
The assignment operator =, relational operators <, ==, and stream operators <<, >> are the most commonly overloaded.