C++ classes as instance variables of an Objective-C class

后端 未结 5 1157
轻奢々
轻奢々 2021-02-10 06:29

I need to mix Objective-C and C++. I would like to hide all the C++ stuff inside one class and keep all the others plain Objective-C. The problem is that I want to have some C++

5条回答
  •  野的像风
    2021-02-10 07:18

    I also ran into this issue recently. In my case a protocol was overkill. I just needed to keep a pointer to a data access object that happened to be a C++ object.

    What I did was declare the class with a void * instance variable and cast it when I use it in the instance methods.

    This is a little bit hack-y, but conceptually, it's very similar to what the Objective-C id type is.

提交回复
热议问题