Mixing Objective C ,(*.m , *.mm & .c /.cpp ) files

I found it imposible to use any Objective-c in the C++ header files.

However, you can include Objective-c in the implementation files.

(.mm or you can set how to interpret .cpp files in the info of the file. Choose Info->General:FileType:Sourcecode.cpp.objcpp )

Use

cppClass.h:

class objcClass;

objcClass* mMemberVariable;

cppClass.mm:

#import "objcClass.h";

void cppFunction(){
    [objcClass message];
}

in the cpp header file.

Then include the header that defines the class in the .cpp or .mm file.


If you have a .cpp file with C++ code that needs to use Objective-C as well, either rename that .cpp file to .mm or pass -x objective-c++ to the compiler.