Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we overload operators for built-in types like int or float?

Tags:

Can we declare a function like this in c++:

int operator + (int , int); 

Your answers will be appreciated!

Thanks

like image 808
Dixit Singla Avatar asked Jul 30 '13 08:07

Dixit Singla


People also ask

Which operators can be overloaded?

The two member access operators, operator->() and operator->*() can be overloaded. The most common use of overloading these operators is with defining expression template classes, which is not a common programming technique.

Which operators Cannot be overload?

(::) Scope resolution operator cannot be overloaded in C language.

Can we overload all operators?

Can we overload all operators? Almost all operators can be overloaded except a few.


Video Answer


1 Answers

You cannot redefine a built-in operator. Operator overloading is designed to allow you to extend the language, not to change it. At least one of the parameters of an overloaded operator must be a user defined type (class or enum type) or a reference to a user defined type.

like image 87
James Kanze Avatar answered Nov 10 '22 05:11

James Kanze