Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C++ classes in Objective - C

I am trying to use some C++ classes in my Objective-C code for an iPhone application. I am just trying to declare the C++ object, and I am running into problems. Even though I am declaring the C++ header file in the Objective-C class I want to use it in, it does not appear that my Objective-C recognizes the C++ object. Here is my Objective-C code:

 //implementation file
#import "CPPClass.h"

@implementation MyViewController
- (void) viewDidLoad
{
    CPPClass object;
}

but I get an "Use of undeclared identifier 'CPPClass'" warning.

How am I supposed to do this?

like image 637
coder Avatar asked May 12 '26 01:05

coder


1 Answers

If you want to use C++ code in Objective-C you need to have it in files with the .mm extension, which the compiler will interpret as Objective-C++ code. You also should #include C++ headers, not #import them.

like image 150
DHamrick Avatar answered May 14 '26 13:05

DHamrick



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!