I want to declare a class c++ style in a objective-c header, but i get an error "error: expected '=', ',', ';', 'asm' or '__ attribute __' before 'CPPClass'"
Here is code from the .h file.
class CPPClass;
@interface OBJCClass : NSObject
{
CPPClass* m_pCPPObject;
}
@end
if i implement it objective-c style @class CPPClass
i get an error when defining it, saying that it can't find the interface declaration. Is there anyway of doing this, otherwise, all the objective-c classes that import my header fi开发者_运维百科le with the imported c++ header must also be .mm files.
ps. i've have renamed the m file to mm.
Declare the cpp class only when compiling C++. Use a typedef to void otherwise:
#ifdef __cplusplus
class CPPClass;
#else
typedef void CPPClass;
#endif
This way, non C++ compilation units see the instance variable as a void pointer. Since all pointers are of the same size, the type of the instance variable does not matter.
Rename any files that include it as having .mm extensions. This will tell the compiler to compile with the -ObjC++
flag.
精彩评论