Re: Circular dependency - I think..

From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 07/26/04


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


Relevant Pages

  • Re: Circular dependency - I think..
    ... >> Note how I used the 'this' pointer in the intitializer list of BAR ... >> to pass a pointer to the created FOO object. ... Thus the destructor of BAR's smart_ptr to FOO is ...
    (comp.lang.cpp)
  • Re: Insert with response
    ... FooBar, there's no way and no need to put them in synch. ... column in the foo table to 250 calumns in the bar table. ... set statistics time off ...
    (microsoft.public.sqlserver.programming)
  • Re: Magic function
    ... processing objects created in root at depth 3 ... root obj2 at depth 3 ... processing objects created in foo at depth 2 ... processing objects created in bar at depth 0 ...
    (comp.lang.python)
  • Re: Method chaining with generics
    ... example, given classes Foo and Bar, under an OO system is one can cast a Foo object to a Bar object, then it is safe to assume that any method on Bar is safely and correctly implemented in Foo. ...
    (comp.lang.java.programmer)
  • Re: from __future__ import absolute_import ?
    ... foo not in bar ... Unfortunately this is a side effect of using the os's directory structure to represent a python "package" structure. ...
    (comp.lang.python)