Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!milano!cadillac!vaughan@mcc.com From: vaughan@mcc.com (Paul Vaughan) Newsgroups: comp.lang.c++ Subject: Re: A solution to the multiple inclusion problem Message-ID: <3531@cadillac.CAD.MCC.COM> Date: 27 Oct 89 14:55:50 GMT References: <14240@well.UUCP> <1989Oct23.191634.6345@cs.rochester.edu> <950@dutrun.UUCP> <1030@ncratl2.Atlanta.NCR.COM> Sender: news@cadillac.CAD.MCC.COM Reply-To: vaughan@mcc.com (Paul Vaughan) Distribution: comp Organization: MCC VLSI CAD Program Lines: 43 In-reply-to: dspoon@ncratl2.Atlanta.NCR.COM (Dave Witherspoon) From: dspoon@ncratl2.Atlanta.NCR.COM (Dave Witherspoon) Say I have 2 classes, A and B. A contains a B*, and B contains an A*. Thus, we have a circular dependency! One proposal (that I've tried): This may not solve your exact problem, but the way to do this is simply in "A.h" class B; class A { B* b; }; and in "B.h" class A; class B { A* a; }; However, this does bring up a real issue. This sort of thing works, but not when you try to define inline functions inside the .h files. Putting inlines in .h files requires the inclusion of other .h files, that would not otherwise be necessary. Since all base class and component types must be defined before a class definition, a single inline function can force a whole tree of .h files to be included, (easily 10 more files) where they would not have been necessary otherwise. Of course, there is no choice when working with ATT's cfront, because inline functions must be defined within the class definition. Also, with GNU g++, inline functions must be defined before they are used, or else they simply can't be inlined. However, at least with the g++ approach, one might structure the files differently, perhaps, including a .inlines.cc file in those files that really need to call inline methods and have them inlined. Does anybody have a reasonable solution for decoupling the .h file dependencies introduced by inlines for either g++ or c++? Paul Vaughan, MCC CAD Program | ARPA: vaughan@mcc.com | Phone: [512] 338-3639 Box 200195, Austin, TX 78720 | UUCP: ...!cs.utexas.edu!milano!cadillac!vaughan