views:

617

answers:

5

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++?

A: 

Yes, there is.

Hank Gay
+6  A: 

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.

Darron
Is 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
Maybe if another company was responsible for the development. Apple has a history of releasing quality software on time.
stealthdragon
+4  A: 

Using C++ With Objective-C

Loki
+10  A: 

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).

Matt Gallagher
Looks like quite a mess...
Adam Byrtek
Works like a charm.
Georg
+1  A: 

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++.

Graham Lee