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:


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

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


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 Headache
The .m compiler will see class and not know what to do..
iPhone OpenGL ES incorrect alpha blending
You can 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 question



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 
#import "OBJCObject.h"  @implementation OBJCObject  @end 
#import "OBJCObject.h"  class CPlus {     OBJCObject *someObj;     CPlus(); };
#include "CPlus.h"  CPlus::CPlus() {     someObj = [[OBJCObject alloc] init]; } 

50 out of 100 based on 55 user ratings 880 reviews