Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Typedefs and operator overloading

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.

like image 434
Anthony Avatar asked Jun 23 '10 07:06

Anthony


People also ask

What is operator overloading with example in C?

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.

Is there operator overloading in C?

C does not support operator overloading (beyond what it built into the language).

What is overloading and operator overloading in C++?

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.

When should operator overloading be used in C?

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.


1 Answers

No. A typedef is actually an alias for another type. The original and typedef-ed types are the same.

like image 140
David Rodríguez - dribeas Avatar answered Sep 27 '22 22:09

David Rodríguez - dribeas