1

I need to pass Objective C object instance to C++ method trough params. How I can do it?

This code doesn't work, and I know it. I'm just showing what I want.

MyObjcClass *instance = [[MyObjcClass alloc] init];
myCppClassInstance.myCppMethod(instance);

1 Answer 1

1

class is a keyword, so it won't work I agree. But for me there are no other issue in your sample code.

Juste declare your cpp method

void myCppMethod(MyObjcClass *obj) {

}

and use it like you did

MyObjcClass *obj = [[MyObjcClass alloc] init];
myCppMethod(obj);
Sign up to request clarification or add additional context in comments.

4 Comments

class word was to show example. of cource I know it :D. But your code doesn't work
fail at compile or runtime ?
it doesn't see MyObcClass header in myCppMethod's class. Check updated code please
Remember to put .mm extension to file using c++ And try : myCppClassInstance->myCppMethod(instance); :)

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.