co-definition of classes

  • The C compiler is happy with the following co-definition of two
    struct types;

    typedef struct Foo {
    struct Bar* bar;
    } Foo;

    typedef struct Bar {
    struct Foo* foo;
    } Bar;

    Is there some way to co-define two classes which reference each other?
    The compiler barfs (error: parse error before 'Bar') at the following:

    #import <Cocoa/Cocoa.h>

    @interface Foo : NSObject {
      Bar* bar;
    }
    @end

    @interface Bar : NSObject {
      Foo* foo;
    }
    @end
  • @class Foo, Bar;

    above your @interface will forward-declare them.

    - d

    On Sep 28, 2007, at 11:34 PM, Roland Silver wrote:

    > The C compiler is happy with the following co-definition of two
    > struct types;
    >
    > typedef struct Foo {
    > struct Bar* bar;
    > } Foo;
    >
    > typedef struct Bar {
    > struct Foo* foo;
    > } Bar;
    >
    > Is there some way to co-define two classes which reference each other?
    > The compiler barfs (error: parse error before 'Bar') at the following:
    >
    > #import <Cocoa/Cocoa.h>
    >
    > @interface Foo : NSObject {
    > Bar* bar;
    > }
    > @end
    >
    > @interface Bar : NSObject {
    > Foo* foo;
    > }
    > @end
  • On Sep 28, 2007, at 8:34 PM, Roland Silver wrote:

    > Is there some way to co-define two classes which reference each other?
    > The compiler barfs (error: parse error before 'Bar') at the following:
    >
    > #import <Cocoa/Cocoa.h>
    > @class Bar;
    > @interface Foo : NSObject {
    > Bar* bar;
    > }
    > @end
    > @class Foo;
    > @interface Bar : NSObject {
    > Foo* foo;
    > }
    > @end

    Obviously, you only need the @class on the one that comes before the
    declaration of the other...

    b.bum
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today