Re: Bi-directional association

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by Daniel Longest on April 15, 2001 at 02:00:52:

In Reply to: Bi-directional association posted by Brian Begnoche on April 14, 2001 at 22:29:04:

Forward declarations can be used when you only need a pointer or I believe a reference to a class. In the case of a derived class, the derived class must know the full class definition of the base (it doesn't need to know the implementation though). In other words, if you do one class:one file, you need to include the base class file in the derived class header. The above is a case where you need the full include. In previous programs where for example, the database was associated with the file manager, you could use a forward declaration in the header file and not have to include the file manager's header until the database source file. In short, include the header for the base in the header for the derived, the source does not need to be included. You can put the derived implemetnation in its file like always and that should all work fine.

: When you have two classes, say a base clase and a derived class, that must know about each other, do you use a forward declaration with the specification of just one class or both of them? I'm having a lot of trouble trying to figure out where to use a forward declaration, where to use an include, and where to have nothing. I'm specifically talking about four files: the header and source files for a base class and the header and source files for a derived class.

Follow Ups:

Post a Followup




Optional Link URL:
Link Title:
Optional Image URL:

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]