If you define a type like typedef int MY_INT;
and go on to overload, say, the adition operator of MY_INT like
MY_INT operator+(MY_INT a, MY_INT b);
will
MY_INT a, b; a + b;
be different from
int A, B; A + B;
?
Sorry for any syntax errors. I'm not near a compiler and I want to ask this before I forget about it.
Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type. For example, C++ provides the ability to add the variables of the user-defined data type that is applied to the built-in data types.
C does not support operator overloading (beyond what it built into the language).
C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.
Two operators = and & are already overloaded by default in C++. For example, to copy objects of the same class, we can directly use the = operator. We do not need to create an operator function. Operator overloading cannot change the precedence and associativity of operators.
No. A typedef is actually an alias for another type. The original and typedef-ed types are the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With