PDA

View Full Version : Objective-C & C++


Indie Mac
2005.01.25, 06:32 PM
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

Jake
2005.01.25, 06:42 PM
Yes, name files with the .mm extension. Compiling will be very slow though.

Indie Mac
2005.01.25, 06:43 PM
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

TomorrowPlusX
2005.01.25, 06:57 PM
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.

MattDiamond
2005.01.26, 03:28 PM
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