Unknown type name 'class' when mixing Objective-C and C++

objective-c, objective-c++

Solution

As you said in a comment, "fooUser.h" is included from non-C++ files as well, and that causes the compiler error. Header files are not compiled separately, but as part of the "compilation unit" from which they are included.

You should try to separate the C++ declarations into a header file that is included only from (Objective-)C++ files.

As a workaround, you could also protect the C++ declarations by

#ifdef __cplusplus
// …
#endif

Problem

This is driving me crazy. I have a C++ class declaration in foo.h file. ``` class foo // error marks are here { }; ``` When I `#include/#import` this header in my fooUser.mm file, it compiles. When I do `#include/#import` it in my fooUser.h file it doesn't, and the compiler errors are. ``` Unknown type name 'class'; did you mean 'Class'? Excpected ';' after top level declarator. ``` I'm using XCode 4.2, LLVM compiler 3.0,... should this be important.

Original source

Related problems