What are the main differences between Objective-C and C++ in terms of the syntax, features, paradigms, frameworks and libraries?
*Important: My goal is not to start a performance war between the two languages. I only want real hard facts. In fact, my question is not related to performance! Please give sources for anything that may seem subjective.
Short list of some of the major differences:
false, Objective-C uses
nullptr, Objective-C prefers
SEL) as an approximate equivalent to function pointers.
nil, unlike C++ which will crash if you try to call a member function of
self, and allows class initialisers (similar to constructors) to return a completely different class if desired. Contrast to C++, where if you create a new instance of a class (either implicitly on the stack, or explicitly through
new) it is guaranteed to be of the type you originally specified.
int foo (void)and
int foo (int)define an implicit overload of the method
foo, but to achieve the same in Objective-C requires the explicit overloads
- (int) fooand
- (int) foo:(int) intParam. This is due to Objective-C's named parameters being functionally equivalent to C++'s name mangling.
allocmessage, or implicitly in an appropriate factory method).
In my opinion, probably the biggest difference is the syntax. You can achieve essentially the same things in either language, but in my opinion the C++ syntax is simpler while some of Objective-C's features make certain tasks (such as GUI design) easier thanks to dynamic dispatch.
Probably plenty of other things too that I've missed, I'll update with any other things I think of. Other than that, can highly recommend the guide LiraNuna pointed you to. Incidentally, another site of interest might be this.
I should also point out that I'm just starting learning Objective-C myself, and as such a lot of the above may not quite be correct or complete - I apologise if that's the case, and welcome suggestions for improvement.
EDIT: updated to address the points raised in the following comments, added a few more items to the list.