views:

168

answers:

3

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?

+6  A: 

C does not allow operator overloading.

Simon
+4  A: 

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.

Georg Fritzsche
+3  A: 

What you need is a Strong Typedef.

Boost offered version that should work for you, or at least help you resolve your need :

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

paercebal