Re: Circular dependency - I think..
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 07/26/04
- Next message: Chris Theis: "Re: do you ever found memory leak with STL?"
- Previous message: Siemel Naran: "Re: STL queue technique"
- In reply to: ma740988: "Circular dependency - I think.."
- Next in thread: ma740988: "Re: Circular dependency - I think.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jul 2004 09:48:30 +0200
ma740988 wrote:
>
> I think I'm caught up in a circular dependency problem. I'd thought
> forward declaration was the solution to my problem but I'm sadly
> mistaken (perphaps i've been in the lab toooo long today).
> The header file for FOO is composed of BAR, likewise BAR is composed
> of FOO.
> If I complile FOO.cpp, Visual Studio's first complaint (C2146 syntax
> error, missing ; before foo - the next complaint is BAR::FOO missing
> storage type) points to the instantiation of FOO in BAR's header(i.e
> the line FOO foo). Similarily if I compile BAR Visual first complaint
> (C2146 syntax error, missing ; before bar - the next complaint is
> FOO::BAR missing storage type) points to the instantiation of BAR in
> FOO's header (i.e the line BAR bar).
given
class FOO
{
int i;
BAR bar;
}
class BAR
{
int j;
FOO foo
};
Now answer a quick question:
What is the size of a FOO object. Assume sizeof(int) == 4
Well: a FOO object consists of an int, that would
be 4 bytes plus the size of an BAR object. That
would be another 4 bytes plus the size of an FOO object.
Which accounts for another 4 bytes plus the size of an BAR
object. Another 4 bytes plus the size of a FOO object.
Add another 4 bytes plus the size of an BAR object ....
(ad infinitum)
Answer: A FOO object would be of unlimited size. I'm quite
sure that your computer doesn't have that much memory.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: Chris Theis: "Re: do you ever found memory leak with STL?"
- Previous message: Siemel Naran: "Re: STL queue technique"
- In reply to: ma740988: "Circular dependency - I think.."
- Next in thread: ma740988: "Re: Circular dependency - I think.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|