• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using C++ classes from Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using C++ classes from Objective C


  • Subject: Re: Using C++ classes from Objective C
  • From: "Clark Cox" <email@hidden>
  • Date: Thu, 20 Mar 2008 12:13:33 -0700

On Thu, Mar 20, 2008 at 11:33 AM, Christopher Nebel <email@hidden> wrote:
> On Mar 20, 2008, at 10:32 AM, Rob Napier wrote:
>
>  > Say you have a C++ object called MyObject in the namespace myapp
>  > that you want to access through your ObjC. What I tend to do is
>  > create an ObjC++ object called MyObjectWrapper that owns a
>  > myapp::MyObject and presents a pure ObjC interface to its methods.
>  > Users of MyObjectWrapper don't have to include MyObject.h. The trick
>  > is that you need to use void* rather than a real class type in
>  > MyObjectWrapper.h like this:
>  >
>  > typedef void* MyObjectPtr
>  >
>  > @interterface MyObjectWrapper : NSObject
>  > {
>  >   MyObjectPtr myObject;
>  > }
>  >
>  > That will get you around having C++ class definitions in your header.
>
>  Actually, you don't need the "void" typedef -- you can exploit the
>  fact that "class" and "struct" are (almost) synonymous in C++:
>
>         struct MyObject; // forward declaration.
>         typedef struct MyObject MyObject; // this is Objective-C, after all...
>
>         @interterface MyObjectWrapper : NSObject
>         {
>                 MyObject *myObject;
>         }

Or just forego the typedef altogether:

@interface MyObjectWrapper : NSObject
{
    struct MyObject *myObject;
}

--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Using C++ classes from Objective C (From: Jeremy <email@hidden>)
 >Re: Using C++ classes from Objective C (From: "Rob Napier" <email@hidden>)
 >Re: Using C++ classes from Objective C (From: John Stiles <email@hidden>)
 >Re: Using C++ classes from Objective C (From: Jeremy <email@hidden>)
 >Re: Using C++ classes from Objective C (From: "Rob Napier" <email@hidden>)
 >Re: Using C++ classes from Objective C (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Using C++ classes from Objective C
  • Next by Date: Re: Using C++ classes from Objective C
  • Previous by thread: Re: Using C++ classes from Objective C
  • Next by thread: Re: Using C++ classes from Objective C
  • Index(es):
    • Date
    • Thread