3

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

tunnuz
  • 23,338
  • 31
  • 90
  • 128

5 Answers5

15

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
  • 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
9

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
  • 21,309
  • 5
  • 49
  • 53
  • 3
    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 Jan 21 '09 at 03:49
  • 2
    Maybe 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
5

Using C++ With Objective-C

Loki
  • 29,950
  • 9
  • 48
  • 62
1

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

0

Yes, there is.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222