views:

133

answers:

2

Hello,

I'm trying to make a simple Objective-C++ applicaiton. All of my code is compiling fine, including the use of C++ in Objective-C classes, until I try and add a C++ class to the mix. I've created a simple C++ class:

Test.h

class Test {

};

and included this file in a Objective-C class (with a .mm extension) and I get the following build error:

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Test'

Clearly I'm missing some simple concept here. I'd appreciate some enlightment.

A: 

Well, after scanning more closely over Apple's Documentation, it looks like the answer to to use the __cplusplus preprocessor flag in the header file. Here's what the code looks like now:

#if __cplusplus

class Test {

};

#endif
helixed
+1  A: 
#if __cplusplus

class Test {

};

#endif

This wil not help, your class will be just skiped by preprocessor if __cplusplus undefined.

Most of all you trying to include C++ class from *.m file, try to rename it to *.mm. This solve the same problem on my side.

Pavel
You're right. I forgot to mention I changed the file extension to .mm. Thanks for the reply.
helixed