Including Objective C++ Type in C++ Class Definition
صفحه اصلي

Including Objective C++ Type in C++ Class Definition



I've got a project that is primarily in C++, but I'm trying to link in a Objective-C++ library. I have a header that looks something like:

CPlus.h:

#import "OBJCObject.h"  class CPlus {   OBJCObject *someObj;  }; 

CPlus.mm:

CPlus::CPlus() {   someObj = [[OBJCObject alloc] init]; } 

When I import the Objective-C++ header into my code I end up with thousands of errors from inside the iPhone SDK. It seems that something is treating one language as if it were another. Sorry if this description is poor, I'm new to this, and am somewhat confused.

Can you include Objective-C / Objective-C++ types in C++ classes? Is there something special you need to do to include the headers for the other types?


How to determine where this memory leak is coming from?

1:

Turn a page like a Book with UIView?
Are you #importing CPlus.h from an Objective-C (.m) file? If so, it will not understand the C++ class since it is being compiled with C semantics, and is not Objective-C++ aware. Does anyone have the UIViewAdditions file from WWDC 2009 session 128? [closed]The .m compiler will see class and not know what to do.. Is there access to the iPhone accelerometer using Javascript? You must include Objective-C objects in C++ class definitions, and vice versa, as long as the source file is .mm.. only character - not special/numbers from keyboard - iPhone
iphone web page transitionsHow to open a new view when touching on a uiview?

2:

UITableView Swipe to delete: how to customize button and action?
The following builds okay with the IPhone SDK. Make sure to declare the c++ constructor, and to implement it in an .mm file.. OBJCObject.h.
#import <Foundation/Foundation.h>  @interface OBJCObject : NSObject { }  @end 
OBJCObject.m.
#import "OBJCObject.h"  @implementation OBJCObject  @end 
CPlus.h.
#import "OBJCObject.h"  class CPlus {     OBJCObject *any Obj;     CPlus(); }; 
CPlus.mm.
#include "CPlus.h"  CPlus::CPlus() {     any Obj = [[OBJCObject alloc] init]; } 


90 out of 100 based on 35 user ratings 150 reviews

*