Re: Bi-directional association


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

Posted by Dave Longley on April 15, 2001 at 17:53:08:

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

I don't know about this base & derived classes needing forward declarations---seems that if that were needed then that would imply a derived class inheriting itself in some manner, but for the sake of this project you will probably need to know this:

header file for Foo1:

class Foo2;

class Foo1
{
Foo2 *ptr;
}

header file for Foo2:

class Foo1;

class Foo2
{
Foo1 *ptr;
}

That takes care of foward declarations.


: 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

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


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