1

I am very new to Objective-C.
I wan to call Objective-C methods from a C++ class defined in separate .cpp file.

I have used the same mechanism described in this question's answer by dreamlax (not the PIMPL one) http://stackoverflow.com/questions/1061005/calling-objective-c-method-from-c-method

But i am stuck at point how to call function int MyCPPClass::someMethod (void *objectiveCObject, void *aParameter); from CPP class with the parameters objectiveCObject.

Also can some one please explain how to call a C++ class functions from Objective-C Code with an Example.

3
  • 1
    I once wrote a very simple example of this as a response to someone's question. Maybe it will give you ideas: stackoverflow.com/questions/13236476/… Commented Nov 28, 2012 at 13:52
  • Thanks for the example, in your 'OCClass.mm' file at the end you have added C++ class implementation. can we move this implementation to separate C++ file? or it should be in that file only. Commented Nov 29, 2012 at 5:17
  • It needs to be in a .mm file because it uses Objective-C code as part of that implementation. I suppose it could be moved into its own file but my habit with O-C++ has been to connect the languages via one pair of classes and implement them together so that I have only one place to look for that code. Commented Nov 29, 2012 at 10:13

1 Answer 1

3

You must use Objective-C++ in the file that does the call. To do so from Xcode, rename the file from Whatever.m to Whatever.mm. Then you can mix calls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.