View Full Version : Mixing Objective-C and C++

Apr 28, 2011, 11:30 PM
I have heard of Objective-C++ and I would like to know if this is possible in Objective-C++. Can I create IBActions that link to buttons and inside these actions I have C++. For example


//Some C++ code


Would something like that work. I would like to do this because I physics engine I would like to use requires C++ and I would like to use this engine inside of a nice Cocoa app with all the interface stuff done in Objective-C.

Apr 28, 2011, 11:40 PM
Assuming the above code is in a .mm file (not a .m file) that should be fine. I don't know about connecting an action directly to C++ method, I don't think that would work. But you should be able to connect it to an objective-c method, and inside that use C++ code, including being able to create C++ object and call C++ methods.

You know Objective-C is an extension to standard C, right? Objective-C++ is the same extension applied to C++.

Apr 29, 2011, 10:32 AM
So inside Objective-C actions I can use C++ methods or no?

Apr 29, 2011, 10:53 AM
So inside Objective-C actions I can use C++ methods or no?

Yes, you can. You will need an Objective-C method to receive the action, but it can simply be a thin layer around a call to a C++ method (on, say, a C++ object that is an ivar of your Objective-C class).


Apr 29, 2011, 11:17 AM