|
|
Cocoa and C++ Question
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Florida
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
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).
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jan 2002
Location: Trondhjem, Norway
Status:
Offline
|
|
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.
|
���
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Florida
Status:
Offline
|
|
Thanks for the replies. I guess it's time to learn some Obj-C.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Seriously, if you know C and you can cope with OO concepts, you can pick up Obj-C in less than an afternoon.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
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).
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|