1

I am following this URL but i have got struck that How can i pass my objective c++(.mm) instance to c++ class. Calling Objective-C method from C++ method?

MyCPPClass.cpp  
#include "MyCPPClass.h"   
#include "MyObject-C-Interface.h"

int MyCPPClass::someMethod (void *objectiveCObject, void *aParameter)     
{  
// To invoke an Objective-C method from C++, use  
// the C trampoline function  
return MyObjectDoSomethingWith (objectiveCObject, aParameter);  
}

How can I call MyCPPClass::someMethod (void *objectiveCObject, void *aParameter) from objective c++(.mm) what can I pass the value for void *objectiveCObject from objective c++(.mm) class.

4
  • You gave a nice working link with an explanation yourself, what exactly doesn't work for you? Commented Feb 16, 2017 at 14:10
  • I am unable to pass objective c instance in .cpp class in method "MyCPPClass::someMethod (void *objectiveCObject, void *aParameter)". How can I pass "void *objectiveCObject" from objective c class. Commented Feb 16, 2017 at 14:14
  • There's another way that works for me, please see: stackoverflow.com/a/42311096/6539779 Commented Feb 18, 2017 at 5:25
  • What do you mean by "can't pass"? Do you get an error message? Commented Mar 4, 2017 at 16:49

1 Answer 1

-1
We can pass instance of objectiveC class to C++  - 

someMethod ((void*)CFBridgingRetain(self),aParameter)
Sign up to request clarification or add additional context in comments.

2 Comments

Hi and welcome to the StackOverflow. I'm afraid that your answer provides no explanation nor context. Could you give a few words explaining what exact problem does your code snippet solves?
While this code may answer the question, providing additional context regarding why and/or how it answers the question would significantly improve its long-term value. Please edit your answer to add some explanation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.