Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!kddlab!titcca!kogwy!wnoc-tyo-news!ascwide!ascgw!cskgw!aoyama!ginny!janis!rac From: rac@macro.co.jp (Robert Coie) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C #include Question Message-ID: Date: 4 Mar 91 09:34:37 GMT References: <1991Feb28.223430.24645@ux1.cso.uiuc.edu> Sender: news@janis.macro.co.jp Organization: Macro Engineering Co., Ltd. Chiyoda-ku Tokyo, Japan. Lines: 48 In-reply-to: dmmg1176@uxa.cso.uiuc.edu's message of 28 Feb 91 22:34:30 GMT In article <1991Feb28.223430.24645@ux1.cso.uiuc.edu>, dmmg1176@uxa.cso.uiuc.edu (David M Marcovitz) writes: >> I am working with 3 classes (call them Foo, Bar, and Baz). Foo and >> Bar are subclasses of Baz. There header files are as follows: >> >> [header files containing mutually recursive Think C classes] >> >> The problem is that I want each Foo to know about a Bar, and I want >> each Bar to know about a Foo. Unfortunately I get a syntax error when >> I try to compile. When compiling Bar.h, it first has to compile >> Foo.h. When Foo.h tries to declare myBar, it can't because the Bar >> class has not been; thus I get a syntax error. >> >> How can I get around this problem? When you define a new class with struct Foo : Baz{}, Think C automatically generates a typedef struct Foo{} Foo; statement for you, enabling you to use the name Foo when referring to instances of this class. I think that the following two structures are similar enough to your Foo and Bar classes to illustrate the problem: typedef struct foo { bar *theBar; } foo; typedef struct bar { foo *theFoo; } bar; As in your example, this will generate a syntax error. Try rewriting it without relying on the typedef: typedef struct foo { struct bar *theBar; } foo; typedef struct bar { struct foo *theFoo; } bar; For more information on this, check the sources for CScrollPane and CPanorama, which are also mutually recursive, or look in your favorite C book about structure tags and incomplete types. -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Robert Coie Love is a vast exaggeration of the difference rac@macro.co.jp between one person and everybody else. - GBS