Is it possible for an Objective-C class to have a instance variable of a C++ interface type?
I can declare a C++ class fine in XCode (it compiles) like so:
class MyClass {
void MyMethod();
}
but if I when I try to declare an interface like this:
interface class MyClass {
void MyMethod();
}
I get an error during compilation: Unknown type name 'interface'
I haven’t even tried to put it in the ObjC class yet, it simply doesn’t compile. Is using C++ interfaces at all possible?
The
interfacekeyword is a Microsoft extension to the language; it doesn’t exist in standard C++. That’s the problem you’re running into. You can’t use them in any C++ program compiled with a non-Microsoft compiler, so given that Microsoft does not produce an Objective-C compiler, no, you can’t use them in Objective-C.Classes or structs can serve the same purpose. AFAIK, interfaces are simply virtual classes that impose some additional constraints, so you’ll just need to make sure to follow those yourself.