Re: #includes
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Thu, 11 Jan 2007 17:21:18 -0600
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:O7Dq$VdNHHA.3288@xxxxxxxxxxxxxxxxxxxxxxx
Neil B <NeilB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Class A has a variable in it's header which is Class B. Class B has a
variable in it's header which is Class A. How do you approach this
so your not chasing your tail??
You don't get into this situation in the first place. Think about it -
what would sizeof(A) be? Class A should be big enough to hold an instance
of B, which in turn should be big enough to hold an instance of A, which
should be big enough to ...
OTOH, if you have pointers instead, then you break the paradox. If that
case the compiler doesn't even need the definition of the other class, it
just needs to know it's data so it will know how big to make the pointer. A
simple forward declaration of the class will suffice:
class A;
class B
{
A* ptr;
};
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: #includes
- From: Carl Daniel [VC++ MVP]
- Re: #includes
- References:
- Re: #includes
- From: Igor Tandetnik
- Re: #includes
- Prev by Date: Re: #includes
- Next by Date: Why would release static lib be significantly larger then my debug build?
- Previous by thread: Re: #includes
- Next by thread: Re: #includes
- Index(es):
Relevant Pages
|