I want to call C ++'sCodeHere, I will summarize my methods,The Hello class is only an encapsulation of Calling C ++ for objective-C..
However, I feel that this is too inconvenient. If there are a lot of C ++ code, it will be very difficult to do so. I hope someone will provide a good solution,ArticleThe demoSource code.
Reference: http://blog.csdn.net/zhouhuiah/article/details/6426158
Write down the demo content
1. Create a new project. I chose "single view application ".
2. Create an objective-C class file named hello
3. There will be two files in the project: Hello. h and hello. M. Change the suffix of the hello. M file to. Mm, that is, hello. Mm.
4. Add the C ++ class to the hello. h file. The content of the hello. h file is as follows:
# Import <Foundation/Foundation. h> @ Interface Hello: nsobject { Class Newhello { Private : Int Greeting_text; Public : Newhello () {greeting_text = 5 ;} Void Say_hello () {printf ( " Greeting_text = % d " , Greeting_text) ;}}; newhello *Hello ;} -( Void ) Sayhellooooo; @ End
5. Implement the sayhellooooo method in the hello. MM file. Call the C ++ class in this method.
# Import "Hello. h"@ ImplementationHello-(Void) Sayhellooooo {hello=NewNewhello (); Hello->Say_hello ();}@ End
6. Use @ Class hello instead of # import or # include to call the C ++ class.
# Import<Uikit/uikit. h>//# Include "Hello. H"@ ClassHello;@ InterfaceViewcontroller: uiviewcontroller {}-(Void) AAAA;@ End
7. Call the methods in the C ++ class
# Import " Viewcontroller. h " @ Interface Viewcontroller () @ End @ Implementation Viewcontroller -( Void ) Viewdidload {[Super viewdidload]; nslog ( @" Dddddddd " ); Hello * AA = [[Hello alloc] init]; [AA sayhellooooo]; // Do any additional setup after loading the view, typically from a nib. } -( Void ) Viewdidunload {[Super viewdidunload]; // Release any retained subviews of the main view. } - (Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation { Return (Interfaceorientation! = Uiinterfaceorientationportraitupsidedown );} -( Void ) AAAA {} @ End
8. Source Code:Objective-C calls C ++Blog park requires that the file name cannot have a plus sign