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?


Unit testing an iPhone static library with XCode 3

1:

Image getting pixelated when used as part of an animation in iPhone animation
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. UITableView Animation HeadacheThe .m compiler will see class and not know what to do.. iPhone OpenGL ES incorrect alpha blending You must include Objective-C objects in C++ class definitions, and vice versa, as long as the source file is .mm.. Does a NSURLConnection retain its delegate?
Which button was tapped… iPhone and Obj-C questionConnection

2:

Can UILabel's drawTextInRect method be overridden to change the size of UILabel's text?
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]; } 


40 out of 100 based on 10 user ratings 860 reviews