[comp.sys.next] How do make Objective-C handle circular class references, HELP!

tenny@ootool.dec.com (Dave Tenny) (02/19/91)

I've read all my NeXT Objc docs, including the more useful and no
longer present with V2.0 Chapter 3 from NexT 1.0 docs on Objc.

If there isn't a solution I have to "undo" a class and inline it as a struct,
doubling the complexity of the class inlining it.  Yuck. (It's a lot
of QuadTree code).

Basically, I have this

... in file X.h ...			... in file Y.h ...

#import "Y.h"				#import "X.h"

@interface X				@interface Y
{					{
  Y *d ;				  X *e ;
 }					}

There's more in the classes of course, but the jist is they are 
cooperating object classes.  But I can't figure any way to get Objective
C to handle these circular references, since it lacks the equivalent of
C++ "Class X" forward declaration construct, and the interfaces aren't the same
as C structure tags.

The only solution I have so far is to make all occurances of
one instance of circular reference (say Y in class X) be
of type "id".  But then they'll all incur extra method lookup, and lose
the static type checking.  Speed is crucial in theses particular objects,
and I like to keep static checking when I can get it.

I tried some macro tricks, but nothing worked satisfactorily.
If you know the solution, please let me know.  This is "real" code, I'm
not just trying to come up with yet-another-complaint about 
yet-another-compiler.  

Many thanks for help...

Dave

tenny@ootool.dec.com (Dave Tenny) (02/19/91)

Following up on my base topic for the question on circular Objc classes,
please note that I used the term "Static binding" loosely for
the Objc method applies when the object receiving the message has a
more specific type than "id".  There is no static binding in Objc
that I know of, though it's supposed (not sure where I read this)
to be a faster method lookup if you to declare explicit classes for
objects.  And if you want to remove the general dynamic method lookups,
you can obtain the method address yourself when you start up, and funcall
it in place of method apply for future calls.  But it's rarely going to
be worth the trouble.

I'm still hoping for a solution to the circular reference problem.
I've had two replies (thanks to those who replied) with what amount to
Objc condolances :-). 

Now, does anybody have a real fix?  Please?

Dave