Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,
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

Code:
-(IBAction)buttonClicked:(id)sender{


//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.
Sincerely,
Blake
 
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++.
 
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).

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.