Calling C++ method from Objective C

Hello,

I have a big trouble that i want to call C++ function from Objective-C but it does not easy for me.

This is the lifecycle:

CategoryScreen.cpp function => iOSBridge.mm function => Call SpeakerViewController.mm => Button press => call function categoryscreen.cpp again.

1.CategoryScreen.cpp function

void CategoryScreen::loadElementIntoViewRecord()
{
>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
>
iOSBridge::addNativeRecordView_iOS(result.size());
#endif
>
}

  1. iOSBridge.mm function

void iOSBridge::addNativeRecordView_iOS(short int rows) {
>
id sth = [[UIApplication sharedApplication] delegate];
>
if ([sth isKindOfClass:[AppController class]]) {
>
SpeakHereViewController *speakViewController = [[SpeakHereViewController alloc] initWithNibName:`“SpeakHereViewController” bundle:nil withManyRows:rows];
speakViewController.view.frame = CGRectMake(585, 275, 156, 494);
AppController *controller = (AppController *) sth;
[controller.viewController.view addSubview:speakViewController.view];

}
}

3.SpeakerViewController.mm

[cell.btn_record addTarget:self action:`selector(recordComplete:) forControlEvents:UIControlEventTouchUpInside];

  1. When recording complete, i want to call void::CategoryScreen updateUI() in CategoryScreen.cpp but how I can call it ?

Please help me, thanks in advance !

I am not sure I fully understand the question but if you want to call a C++ function you need a target instance of the class and a pointer to its relevant method
then you call it:
(instance->*function)(args);

This should help: http://stackoverflow.com/questions/4456239/calling-c-method-from-objective-c

You can mix C/C++ and Objective-C in the same file, so you can just call your C function like you would normally. Make sure the file type is saved with a “.mm” extension, or manually change the compile type to “Objective C++”.

Ben

thank for your answers. it’s useful for me. I changed from cpp extension to mm. and i could do it.