views:

45

answers:

2

1) Refcounted pointers need stack variables to have constructors / destructors called at predictable places.

2) Objective-C, afaik, does not support the above.

3) The cocoa libraries are bound in Objective-C, not C++.

Thus, my question: is there a easy way to use the Cocoa libraries, yet still have most of my app in C++ (and thus use my refcounted pointers)?

Thanks!

(iPhone in the title since this is mainly targeted at the iPhone)

+1  A: 

Yes, you can use Cocoa with C++. The gcc compiler will compile code that contains both C++ and Objective C constructs; the resulting language is called (somewhat predictably) Objective C++.

Martin B
A: 

If you name your files with a .mm extension instead of .m, the compiler will assume that you are using Objective-C++ in them.

Although, frankly, unless some of your code needs to be cross platform, there is little point in bothering with C++. Apart from the fact that the OO in Objective-C is more like proper OO, some of the Xcode tools work with Objective-C but not Objective-C++ e.g. the static analyser (very useful).

JeremyP