Overloading operators in Objective-C

boyfarrell

Registered
Hi everyone,

I think I remember reading somewhere that it's impossible to overload + * - / operators in objective-c. Just thought I'd check it out.

(It would make my Vector class easier to read etc if I could have a MATLAB type functionality,C = A .* B for Vectors. At them moment it's something like [myVectorC equalsVector: myVectorA multiplyBy: myVectorB];)
 
C++ is the way to go if you want easily readable mathematical code. The language itself has many flaws, but operator overloading isn't one of them especially if you write lots of numerically intensive code.
 
Is is just me or does anyone think that mixing Objective-C with C++ code is going to result in some really ugly mess of code?
 
Not if done right. If you're using a C++ library there really isn't any other way. Just declare your C++ classes as pointers (a must as the default constructor doesn't get called) and handle them like any other pointer, using "delete" to free them on dealloc.
 
Back
Top