CPB Mailing List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: basic OOD question.
Takaaki,
First off, the compiler errors are telling you that you are including class
headers multiple times, either thru header files referencing each other
(header A includes header b and header B includes header A) or you are
recursively including the same header file (usually because you have not
included the #ifndef SOMEHEADERNAME #define SOMEHEADERNAME construct to
prevent a header file being included more than one time in a compilation unit.
BCB adds this to its header files but you have to add it your own source code.
In the case of two or more header files referencing each othe,r the problem is
that the compiler cannot complete the processing of one class definition
before it encounters the included class definition which references the first
class definition (they have reached impasse). This can be resolved by
providing a forward class reference in one or both of the header files. For an
example of this take a look at any one of the many VCL source code libraries.
This mechanism is used to work around the "What came first, chicken and the
egg?" situation.
As to the location for making the declarations I would recommend that you
allow BCB to autocreate the applications main form. You could add the
additional creation commands to the main form's constructure. Make sure that
you properly set the references between classes (in both directions if required).
Von R. Colborn
Cornerstone Systems, Inc.
Takaaki Yagi wrote:
>
> Hello
> I can't implement classes completely.
>
> Suppose that I wrote class Form, Appli, A, and B.
> This means there are units called Form.cpp, Appli.cpp, A.cpp, and B.cpp.
> And I want to make relations between Appli and Form, Appli and A, and Appli
> and B.
>
> At first, where should I make a persistent (exists as long as the
> Application runs)instance like
> Form* pF = new Form;
> Appli* pAp = new Appli;
> A* pA = new A;
> B* pB = new B;
>
> I want to make pAp which can access pF, pA, and pB.
> And I want to make pF which can access only pAp.
>
> I tried some way but error massages like "multiple declarations" or "include
> files nested too many" appear.
> Can you help me?
> Thank you.
>
> Taka Yagi b101ttt@mxc.mesh.ne.jp
> Phone 001-81-0166-33-4729
> Website http://www2s.biglobe.ne.jp/~exp/index.htm
W Komornicki's Home Page |
Main Index |
Thread Index