Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa and C++ Question

Cocoa and C++ Question
Thread Tools
gserv2
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Florida
Status: Offline
Reply With Quote
Apr 1, 2004, 11:25 PM
 
Is it possible to use C++ with Interface Builder and Cocoa? Most of the programming stuff I've seen for Mac deals with Obj-C; I never see any C++ tutorials or books. A lot of the Carbon stuff I see is in C++. So what are some common uses for C++ on the Mac? I'm interested in making small, simple GUI apps with Project Builder or maybe a preference panel for System Preferences, but I don't know Obj-C.

     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 2, 2004, 12:49 AM
 
Cocoa is compatible with Java and Objective-C (and Ruby, I think, but that's unofficial). C++ is used for Carbon apps, or with cross platform toolkits. I would just learn Objective-C, it's gonna take a lot less effort than learning Cocoa or Carbon is (and you'll have to learn one of those anyway).
     
alien
Mac Enthusiast
Join Date: Jan 2002
Location: Trondhjem, Norway
Status: Offline
Reply With Quote
Apr 2, 2004, 02:55 PM
 
To interact with the Cocoa frameworks most developers use Obj-C, and to a lesser degree Java. (Some scripting languages might apply as well, I don't know much about that.) C++ lacks some features (notably dynamism) that's needed with Cocoa.

But you can in fact mix Obj-C and C++ code in a single source file, and let objects written in each language work with each other. This is called Objective-C++ and works because both languages are different supersets of C, so there's no ambiguity.
זרו
     
gserv2  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Florida
Status: Offline
Reply With Quote
Apr 2, 2004, 07:57 PM
 
Thanks for the replies. I guess it's time to learn some Obj-C.

     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 3, 2004, 05:13 AM
 
Seriously, if you know C and you can cope with OO concepts, you can pick up Obj-C in less than an afternoon.
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 3, 2004, 01:33 PM
 
Originally posted by Angus_D:
Seriously, if you know C and you can cope with OO concepts, you can pick up Obj-C in less than an afternoon.
Took me about a week, mostly to get the hang of memory management.
     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 3, 2004, 04:21 PM
 
Originally posted by Catfish_Man:
Took me about a week, mostly to get the hang of memory management.
Well, that's strictly Cocoa not Obj-C itself

Anyway, I don't see why people make such a big deal of memory management in Cocoa. Reference counting is a pretty standard concept (for example a lot of the other C-based APIs in OS X use it now, CFRetain/CFRelease and so on), all Cocoa adds is -autorelease which is pretty easy to get a handle on (the object is marked "to be released later", specifically it is placed in the current autorelease pool which by default is created at the beginning of each cycle through NSApplication's event loop and destroyed at the end).
     
Ghoser777
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 05:49 PM
 
Oh... now it makes so much more sense to me after that explanation

It just depends on what you're coming from - if you had to worry much about memory management before or not. There's just a couple rules you have to remember when creating and returning objects, and the more practice you have with it (and the more fun you have debugging memory leaks and illegal memory access errors) that better Obj-C programmer you'll become.

Matt Fahrenbacher
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 3, 2004, 06:52 PM
 
Originally posted by Angus_D:
Well, that's strictly Cocoa not Obj-C itself

Anyway, I don't see why people make such a big deal of memory management in Cocoa. Reference counting is a pretty standard concept (for example a lot of the other C-based APIs in OS X use it now, CFRetain/CFRelease and so on), all Cocoa adds is -autorelease which is pretty easy to get a handle on (the object is marked "to be released later", specifically it is placed in the current autorelease pool which by default is created at the beginning of each cycle through NSApplication's event loop and destroyed at the end).
I started out with C++, but never really learned it in that, then switched to Java (still didn't really learn it, since it didn't do bad things to me if I didn't). So I'm sure you can imagine the number of memory errors my programs had at first.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:42 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,