• 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: How is this possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How is this possible?


  • Subject: Re: How is this possible?
  • From: "Jonathan del Strother" <email@hidden>
  • Date: Sun, 20 Apr 2008 16:32:21 +0100

On Sun, Apr 20, 2008 at 4:25 PM, Don Arnel <email@hidden> wrote:
> I have two different class objects that need to know about each other (see
> below). But if I include the header from one class inside the header of the
> other class the compiler complains. Is this even possible?
>
>  ClassOne.h:
>  ----------------
>
>  #import "ClassTwo.h"
>
>  @interface ClassOne : NSObject {
>
>         ClassTwo *objectTwo;
>  }
>
>  @end
>  ----------------
>
>
>  ClassTwo.h:
>  ----------------
>
>  #import "ClassOne.h"
>
>  @interface ClassTwo : NSObject {
>
>         ClassOne *objectOne;
>  }
>
>  @end



Pre-declare the classes with '@class' - eg

@class ClassTwo;
@interface ClassOne : NSObject {

       ClassTwo *objectTwo;
}

@end

You'll still need to import 'ClassTwo.h' in your implementation file.

It's a good idea to do that instead of importing any of your own
headers within header files.  Things can get a bit contorted
otherwise.
_______________________________________________

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: 
 >How is this possible? (From: Don Arnel <email@hidden>)

  • Prev by Date: Re: How is this possible?
  • Next by Date: Re: Should a Method set NSError* to nil when No Error?
  • Previous by thread: Re: How is this possible?
  • Next by thread: Passing a C String as an argument
  • Index(es):
    • Date
    • Thread