Typedef and operator overloading in C ++

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

typedef int int2 

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

How to achieve int overloading and, in addition, use * for int as they are. Should I create a new type?

+6
c ++ operator-overloading
source share
3 answers

What you need is a Strong Typedef .

Improve the suggested version that should work for you, or at least help you solve your problem:

http://www.boost.org/doc/libs/1_42_0/boost/strong_typedef.hpp

+4
source share

Assuming you're talking about C ++:
Operator overloads must accept at least one user-type argument. typedef does not change anything since it does not introduce a new type and provides only a synonym.

+9
source share

C does not allow operator overloading.

+5
source share

All Articles