Take the 2-minute tour ×

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.

share|improve this question
Thank you for all the help! –  Alerty Mar 15 '10 at 4:36
On a scale of 1 to 10, I'd put the difference at about 6 or 7. –  jeffamaphone Mar 17 '10 at 0:48
I wish I could accept multiple answers. –  Alerty Mar 22 '10 at 21:47
But accept at least one then! –  Oskar Kjellin Apr 2 '10 at 14:24
it's pretty annoying how stack overflow have closed all the most interesting questions on stackoverflow. not every question has a binary answer, but it is still a question, and a damn sight more interesting! –  Dominic Tobias Nov 13 '13 at 11:42
show 3 more comments

closed as not constructive by Bo Persson, interjay, Tom Seidel, Pfitz, VMAtm Oct 31 '12 at 10:37


8 Answers

up vote 32 down vote accepted

This guide gives the best comparison I've seen.

share|improve this answer
add comment

Short list of some of the major differences:

  • C++ allows multiple inheritance, Objective-C doesn't.
  • Unlike C++, Objective-C allows method parameters to be named and the method signature includes only the names and types of the parameters and return type (see bbum's and Chuck's comments below). In comparison, a C++ member function signature contains the function name as well as just the types of the parameters/return (without their names).
  • Objective-C uses "selectors" (which have type SEL) as an approximate equivalent to function pointers.
  • Objective-C uses a messaging paradigm (a la Smalltalk) where you can send "messages" to objects through methods/selectors.
  • Objective-C allows for dynamic dispatch, allowing the class responding to a message to be determined at runtime, unlike C++ where the object a method is invoked upon must be known at compile time (see wilhelmtell's comment below). This is related to the previous point.
  • Objective-C allows autogeneration of accessors for member variables using "properties".
  • Objective-C doesn't allow implicit method overloading, but C++ does. That is, in C++ 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) foo and - (int) foo:(int) intParam. This is due to Objective-C's named parameters being functionally equivalent to C++'s name mangling.
  • Objective-C doesn't allow objects to be created on the stack - all objects must be allocated from the heap (either explicitly with an alloc message, or implicitly in an appropriate factory method).
  • Like C++, Objective-C has both structs and classes. However, where in C++ they are treated as almost exactly the same, in Objective-C they are treated wildly differently - you can create structs on the stack, for instance.

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.

share|improve this answer
Decent list; one correction. They aren't "named parameters", but "interleaved parameters". Named and "keyword arguments" lead to confusion of thinking that some subset of the method name may be omitted. It cannot. –  bbum Mar 15 '10 at 7:04
You forgot to enlist the most important difference: Object-C uses dynamic dispatch, whereas C++ uses static dispatch. In other words, code compiled by an Objective-C compiler will have the class responsible for responding to a message determined at runtime; code compiled by a C++ compiler have this information calculated and compiled-in at compiletime. –  wilhelmtell Mar 15 '10 at 19:15
Just a slight correction to the second point: A method's name in Objective-C is called its selector — the method signature refers to the types the method takes and returns (see, for example, the NSMethodSignature class). –  Chuck Mar 15 '10 at 22:39
@wilhelmtell: The C++ compiler knows only the superclass at compile time. At run time the actual class could be any descendant. This is also a form of dynamic dispatch, but not the same form as is used in Objective C. Just be careful with those technical terms! –  Norman Ramsey Mar 16 '10 at 1:15
+1 Good list. However, Objective-C also uses void* and NULL, just not for objects. You can use any C-style pointer in Obj-C, and many API calls actually pass or return values by reference, in which case NULL is frequently used. –  Quinn Taylor Mar 16 '10 at 2:49
show 8 more comments



Regarding libraries, you can use plain C libraries in both languages - but their native libraries are completely different.

Of interest though is that you can mix both languages (with some limitations). The result is called Objective-C++.

share|improve this answer
add comment

They're completely different. Objective C has more in common with Smalltalk than with C++ (well, except for the syntax, really).

share|improve this answer
add comment

Off the top of my head:

  1. Styles - Obj-C is dynamic, C++ is typically static
  2. Although they are both OOP, I'm certain the solutions would be different.
  3. Different object model (C++ is restricted by its compile-time type system).

To me, the biggest difference is the model system. Obj-C lets you do messaging and introspection, but C++ has the ever-so-powerful templates.

Each have their strengths.

share|improve this answer
add comment

Objective-C is a more perfect superset of C. In C and Objective-C implicit casting from void* to a struct pointer is allowed.

Foo* bar = malloc(sizeof(Foo));

C++ will not compile unless the void pointer is explicitly cast:

Foo* bar = (Foo*)malloc(sizeof(Foo));

The relevance of this to every day programming is zero, just a fun trivia fact.

share|improve this answer
add comment

As others have said, Objective-C is much more dynamic in terms of how it thinks of objects vs. C++'s fairly static realm.

Objective-C, being in the Smalltalk lineage of object-oriented languages, has a concept of objects that is very similar to that of Java, Python, and other "standard", non-C++ object-oriented languages. Lots of dynamic dispatch, no operator overloading, send messages around.

C++ is its own weird animal; it mostly skipped the Smalltalk portion of the family tree. In some ways, it has a good module system with support for inheritance that happens to be able to be used for object-oriented programming. Things are much more static (overridable methods are not the default, for example).

share|improve this answer
add comment

Obj-C has much more dynamic capabilities in the language itself, whereas C++ is more focused on compile-time capabilities with some dynamic capabilities.

In, C++ parametric polymorphism is checked at compile-time, whereas in Obj-C, parametric polymorphism is achieved through dynamic dispatch and is not checked at compile-time.

Obj-C is very dynamic in nature. You can add methods to a class during run-time. Also, it has introspection at run-time to look at classes. In C++, the definition of class can't change, and all introspection must be done at compile-time. Although, the dynamic nature of Obj-C could be achieved in C++ using a map of functions(or something like that), it is still more verbose than in Obj-C.

In C++, there is a lot more checks that can be done at compile time. For example, using a variant type(like a union) the compiler can enforce that all cases are written or handled. So you don't forget about handling the edge cases of a problem. However, all these checks come at a price when compiling. Obj-C is much faster at compiling than C++.

share|improve this answer
add comment
