On 17.12.2009, at 20:24, Randall Meadows wrote:
> Just like that.  Put this into a .mm file, and it'll compile as 
> Objective-C++.  You'll get a compiler warning that objcptr may not respond to 
> updateText, which you can eliminate by casting objcptr to the appropriate 
> class.

 By the way, neat trick:

The header <objc/objc.h> is a C-language header implementing the runtime. It 
defines some standard types used by Objective-C, including id. So if you 
include this, your headers can use the "id" data type even if they're included 
from plain C++ or C files. I.e. your header and source file would be:

// MyClass.h

#include <objc/objc.h>

class MyClass
{       
public:
        id   objcptr; // ptr to my obj-c object
        void CallOBJC(void);
}

// MyClass.mm

MyClass::CallOBJC()
{
        [objcptr updateText];
}

You can't ObjC-style qualify the "id" with a category, as in 
"id<MyUpdateTextProtocol>", but it's a tad more elegant.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.lookandfeelcast.com

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to