Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C++ and .cpp files in Xcode

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.

like image 258
LandonSchropp Avatar asked May 19 '26 06:05

LandonSchropp


1 Answers

helixed's answer will 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.

like image 85
Pavel Avatar answered May 21 '26 19:05

Pavel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!