简体   繁体   中英

Accessing ivars of an objective-c class within c++ function

I have an objective-c class, which has a string ivar which I need to change when a callback function is called. The trouble is that the callback is in c++, and I therefore cannot access the ivars of the objective-c class in that c++ function. The callback must be in c++ that, cannot change. I realize that there are other ways this could be done ie a global variable which is set by that function and read by my class, or a wrapper c++ class which contains the function and a string and is a member of my objective-c class. However I feel that simply setting the ivar within the callback would be the simplest and cleanest way to do it. Anyone know of a way to do such a thing?

我将在Objective-C类上使用getter / setter并将其作为上下文信息传递给函数。

This seems you need to code c++ and objective C in the same code

so just add extension of the file as .mm and just can write c++ and objective c easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM