• 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: Referring to Other Classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Referring to Other Classes


  • Subject: Re: Referring to Other Classes
  • From: Derrick Bass <email@hidden>
  • Date: Sun, 21 May 2006 02:00:10 -0500

On May 19, 2006, at 5:44 PM, Kris Rambish wrote:

Since I am building a framework I cannot include the header for the C++ classes in my wrapper.h (this is the file that is now public to applications using the framework). Otherwise every application that uses my framework will have to be Objective-C++. In addition, when I try to do this any application that is using the framework can never resolve the location of the C++ header files.


A simple solution, but one that I'm not SURE will work. I think that since you are just using pointers to the C++ classes in your interface, you can get away with just forward declaring structs in the .h file:
#import <Cocoa/Cocoa.h>
struct CpluspplusClass1, CpluspplusClass2;


@interface WrappedObject : NSObject
{
	CpluspplusClass1 *object1;
       CpluspplusClass2 *object2;
}

If that doesn't work, then it should be fine to declare them as void* in the interface and cast back and forth in the implementation.

You can also completely hide the implementation details inside your framework. There are two ways to do that. One would be to have all the C++ interaction handled by a private class:

#import <Cocoa/Cocoa.h>

@class WrappedObjectImpl;

@interface WrappedObject : NSObject
{
	WrappedObjectImpl *impl;
}
-(int) getValue;
-(int) DoSomethingAndReturn:(int)i;
@end

------------------------------------------------------------------------ ------------
wrapper.mm


#import "wrapper.h"
#import "WrappedObjectImpl.h"
#import "cplusplusheader.h"

@implementation WrappedObject
-(int) getValue
{
    return [impl getValue];
}

-(int) DoSomethingAndReturn:(int)i
{
    return [impl DoSomethingAndReturn];
}
@end


Then in WrappedObjectImpl.{h,mm} you would put what you currently have in wrapper.{h,mm}. You could also just inline the interface and implementation of WrappedObjectImpl in wrapper.mm


The second way would be make WrappedObject into a sort of class cluster (with just one concrete class). So WrappedObject would just be an abstract interface and its init function would actually return an object of type WrappedObjectImpl*. That would avoid the need to write all those forwarding functions and avoid the extra level of indirection.

Derrick

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Referring to Other Classes (From: email@hidden (Kris Rambish))

  • Prev by Date: Re: Newbie Q : communication problem with NSTableView
  • Next by Date: Re: Newbie Q : communication problem with NSTableView
  • Previous by thread: Re: Referring to Other Classes
  • Next by thread: [ANN] -- Ambrosia seeks Cocoa programmer
  • Index(es):
    • Date
    • Thread