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 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.
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).
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.