On Feb 23, 2011, at 10:47 AM, James Bucanek wrote:

> Greetings,
> 
> I searched the list, and Apple's documentation, and couldn't 
> find an answer to this (simple) question.
> 
> I have a couple of large Cocoa projects that suddenly need to 
> use some C++ libraries (3D graphics stuff). I assume that I can 
> simply start creating Objective-C++ classes to contain this 
> code, but I'm wondering how to cleanly integrate the new 
> Objective-C++ classes with the existing Objective-C classes. 
> Naturally, I need to send messages from my Objective-C classes 
> to my Objective-C++ classes, and vice versa.
> 
> Specifically, I create an Objective-C++ class that contain C++ 
> object references and types in its @interface declaration. How 
> can I #import this into an Objective-C module? The Objective-C 
> won't understand any of the C++ class names or types.


You can't, but you can declare protocols for your ObjC++ classes in separate 
headers then have the ObjC classes interact with "NSObject<Foo>" instead of Foo 
objects directly.

FooProtocol.h

@protocol Foo
// methods the pure ObjC classes need to see 
@end

Foo.h

#import "FooProtocol.h"
@interface Foo : NSObject <Foo>
...

Foo.mm
#import "Foo.h"
// do C++ things here

Bar.m

#import "FooProtocol.h"
// do things with NSObject<Foo> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to