Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef and operator overloading in C++

Suppose I typedef an integer or integer array or any known type:

typedef int int2

Then I overload operator * for int2 pairs, now if I initialize variables a and b as int. Then will my * between a and b be the overloaded * ?

How do I achieve overloading an int and yet also use * for int the way they are. Should I create a new type?

like image 629
Jose Avatar asked May 16 '10 17:05

Jose


1 Answers

Assuming you are talking about C++:
Operator overloads have to take at least one argument of user-defined type. The typedef doesn't change anything, as it does not introduce a new type and only provides a synonym.

like image 60
Georg Fritzsche Avatar answered Sep 19 '22 19:09

Georg Fritzsche