Is there a way to include an objective-c header from a cpp? Because when I try to #include "cocos2d.h" from a cpp .h file, a lot of errors complaining about @'s and -'s are showing up.
Can c++ files include obj-c headers like that?
Is there a way to include an objective-c header from a cpp? Because when I try to #include "cocos2d.h" from a cpp .h file, a lot of errors complaining about @'s and -'s are showing up.
Can c++ files include obj-c headers like that?
It is possible, but you need to use Objective-C++ (e.g. by making the file extension .mm) to mix the languages, plain C++ sources don't work.
To make that clear:
.m files only allow Objective-C sources.cpp files only allow C++ sources.mm allow mixed Objective-C++ sources - i.e. both Objective-C and C++ with some limitationsIf you need to keep the two worlds seperated instead you need to write wrapper classes that hides the Objective-C details from C++ and vice versa.
.mm this should be no problem, you might want to ask about that instead with more details. In the header this is fine as long you don't include it in plain .m files.C++ has no idea what Objective-C is. So including an Objective-C .h in a .cpp is a no-go.
The other way around, though is fine, if you use the .mm file extension (Objective-C++) instead of .m (Objective-C).
#ifdef __OBJC__ … #endif to prevent it from being parsed.It is possible when you are compiling with mixed objc/c++. Cocoa applications can be written in languages mix in both directions: you can either use an obj-c class inside the C++ or a C++ class inside a obj-c object.
I assume in your case you are compiling pure C++ app where the obj-c code is not allowed.