Re: When and how often do you mix C++ with Objective C in your project?
Re: When and how often do you mix C++ with Objective C in your project?
- Subject: Re: When and how often do you mix C++ with Objective C in your project?
- From: Peter N Lewis <email@hidden>
- Date: Fri, 31 Oct 2008 10:30:57 +0900
AI am a newbie to the cocoa world (PC -> Mac switcher). I have a
fair amount of experience coding in C and C++ and I am just getting
into Obj C now. Right now I am trying to learn the language idioms
and patterns in the Obj C world, specifically, when do you find
yourself mixing C++ code with your Obj C code in your project? How
often do you do that? What's the pros and cons of doing that?
Keyboard Maestro was written entirely in in C++/Carbon. There were a
couple useful Cocoa classes, so I mixed them in (eg Cocoa has a
method to expand ~ in file paths).
When it was time to start moving to Cocoa more seriously, I just
turned the compiler on to Objective C++ for the entire project,
recompiled and there was essentially no change (no size or speed
changes were noticeable). Then I just started writing Cocoa objects
for various UI. Many of my Cocoa objects have a C interface to
create them and a C++ pointer as a "delegate" to interface with.
About the biggest issue is that you cannot have C++ objects in an
Objective C object (their constructors and destructors wont be
called). You can happily have pointers to C++ objects though, you
just have to manage the creation and destruction yourself (which can
be a bit of a pain in Cocoa as there is no single constructor place -
but fortunately (or not) you wont be using Garbage Collection any
time soon so at least dealloc is a single point for removal in most
cases).
You also need tor read the Apple docs on mixing Carbon & Cocoa.
Introduction to Carbon-Cocoa Integration Guide
<http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/CarbonCocoaDoc.html>
But basically, "it just works". There isn't much pain with simply
using Objective C++ and writing parts of your code in Cocoa.
Enjoy,
Peter.
--
Keyboard Maestro 3 Now Available!
Now With Status Menu triggers!
Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/> <http://download.stairways.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden