I'm reading a post about iPhone programming and I've noticed that the talk about Objective C++, the code shown in the post looks mainly like Objective-C but there also are several snippets in C++. Is it really possible to program Cocoa from C++?
5 Answers
In addition to the other comments, I would add that Objective-C++ is not exactly the same as "program Cocoa from C++" because there is no C++ to Cocoa bridge involved.
In Objective-C++, you program the Cocoa API entirely with Objective-C objects/syntax. The Cocoa API remains unchanged, so you need to communicate with it in the same way (using Objective-C strings, Objective-C arrays and Objective-C objects).
The difference with Objective-C++, compared to plain Objective-C, is that you can also use C++ objects (containing Objective-C objects, contained by Objective-C objects or just along-side Objective-C objects).

- 14,858
- 2
- 41
- 43
-
Using it all the time - can be awkward at times but in general great for anything cross-platform, re-using existing business code, open source libraries, ... – Jay Mar 27 '13 at 12:57
Yes. Basically, Objective-C is a set of Smalltalk like object extensions to C. Objective C++ is the result of applying those same extensions to C++. This leaves you with a language with two different object models.
Apple's xcode development environment provides both an Objective-C and Objective-C++ compiler.

- 21,309
- 5
- 49
- 53
-
3Is it just me or does the prospect of writing code in an environment with two different object models sound like a recipe for disaster to anyone else? – Michael Kohne Jan 21 '09 at 03:49
-
2Maybe if another company was responsible for the development. Apple has a history of releasing quality software on time. – calvinlough Jan 04 '10 at 21:06
It's actually an easter egg in the Apple documentation to check whether anybody's reading - the same person wrote all of the WebScript documentation in the WO4 guides.
Yes, there is Objective-C++.