Objective-C & C++

Indie Mac
Unregistered
 
Post: #1
Is it possible to mix C++ source code with Objective-C source code (useful for porting a PC game to Cocoa). Any problems/fyi's to know about, if it is possible?

Thanks,

Mark
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #2
Yes, name files with the .mm extension. Compiling will be very slow though.
Quote this message in a reply
Indie Mac
Unregistered
 
Post: #3
So could an ordinary ObjC (no C++ code used) be .mm as well (for simplistic sake...). Also, is it just compile times, or are run times slow as well? Thanks for your prompt reply.

Mark
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
Run time is fine. It's just a hit at compile time.

Personally, when I need to do stuff like this, I just make a wrapper C++ class with a pure C++ header file. Then C++ code can call the wrapper without needing to be Objective-C++.

For example, just a few days ago I wrote a complete C++ binding to NSUserDefaults and NSDictionary, using stl::map and the like as my C++ datatype. very clean, very easy to call from pure C++ code.
Quote this message in a reply
Moderator
Posts: 437
Joined: 2002.09
Post: #5
I recently described how I keep my own C++ and ObjC++ code segregated in this thread: http://www.idevgames.com/forum/showthread.php?t=8221

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Post Reply