On 31 okt 2008, at 02.30, Peter N Lewis wrote:

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 can invoke the constructors and destructors yourself, using placement new. Also, supporting GC is no big deal:
simnply add a finalize method to destroy c++ objects.
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/tommy.nordgren%40comhem.se

This email sent to [EMAIL PROTECTED]

----------------------------------
The three things an undertaker should never say to a client:
-Nice doing business with you.
-Welcome back.
-Have a nice day. (The King of ID)
----------------------------------
Tommy Nordgren
[EMAIL PROTECTED]



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to