# Overloading operators in Objective-C



## boyfarrell (Jan 2, 2006)

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]


----------



## kainjow (Jan 2, 2006)

Yes, it's not a feature of Objective-C, just C++.


----------



## Viro (Jan 3, 2006)

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.


----------



## boyfarrell (Jan 3, 2006)

In general I'm happy with Objective-C so think I'll stick with it. Cheers, for that. Dan.


----------



## HateEternal (Jan 3, 2006)

boyfarrell said:
			
		

> In general I'm happy with Objective-C so think I'll stick with it. Cheers, for that. Dan.



Don't forget that Obj-C can use C++ libraries (and java too I think) so if you needed to bust out the C++ for some crazy math you could still use obj-c for the builk of your program.

http://developer.apple.com/document...eC/LanguageOverview/chapter_4_section_10.html


----------



## Viro (Jan 3, 2006)

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?


----------



## kainjow (Jan 3, 2006)

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.


----------

