By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

compilation problem... WHY?

P: n/a
Welcome,
I will simplyfy my problem...

There are 3 classes in 3 files(actually 6, *.h and *.cpp). Every class uses
2 others.
These are *.h:
--------------------
....
include <B.h>
include <C.h>
....
class A
{
B b;
C c;
....
}
--------------------
....
include <A.h>
include <C.h>
class B
{
A a;
C c;
....
}
--------------------
....
include <A.h>
include <B.h>
class C
{
A a;
B b;
....
}

Why it dosn't compile? Unless I put before each class declaration of others:
class B;
class C;
etc...

Is it only solution?

Thanks,
Dariusz
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dariusz Plygawko wrote:
Welcome,
I will simplyfy my problem...

There are 3 classes in 3 files(actually 6, *.h and *.cpp). Every class uses
2 others.
These are *.h:
--------------------
...
include <B.h>
include <C.h>
...
class A
{
B b;
C c;
...
}
--------------------
...
include <A.h>
include <C.h>
class B
{
A a;
C c;
...
}
--------------------
...
include <A.h>
include <B.h>
class C
{
A a;
B b;
...
}

Why it dosn't compile? Unless I put before each class declaration of others:
class B;
class C;
etc...

Is it only solution?

Thanks,
Dariusz


I'm sure there's a FAQ on circular dependencies.

In addition, your includes should use "A.h", "B.h", and "C.h", instead of <A.h>, etc...
Angle bracketed includes are for standard include files.
Jul 22 '05 #2

P: n/a
red floyd wrote:
Dariusz Plygawko wrote:
Welcome,
I will simplyfy my problem...

There are 3 classes in 3 files(actually 6, *.h and *.cpp). Every class
uses
2 others.
These are *.h:
--------------------
...
include <B.h>
include <C.h>
...
class A
{
B b;
C c;
...
}
--------------------
...
include <A.h>
include <C.h>
class B
{
A a;
C c;
...
}
--------------------
...
include <A.h>
include <B.h>
class C
{
A a;
B b;
...
}

Why it dosn't compile? Unless I put before each class declaration of
others:
class B;
class C;
etc...

Is it only solution?

Thanks,
Dariusz


I'm sure there's a FAQ on circular dependencies.

In addition, your includes should use "A.h", "B.h", and "C.h", instead
of <A.h>, etc...
Angle bracketed includes are for standard include files.


Everything the OR has mentioned is correct -- but there's a deeper
problem here. In the example the OP provided, how big is an instance
of class A?

Think about it. ;-)

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 22 '05 #3

P: n/a
In article <bq**********@sunnews.cern.ch>, Dariusz Plygawko
<Da**************@cern.ch> writes:
Why it dosn't compile? Unless I put before each class declaration of others:
class B;
class C;
etc...

I can't tell exactly what your problem is, but according to your example it
seems that your classes are recursiv. The compiler can't figure out when to
stop solving depencies and simply stops.

----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email ab***@newsone.net
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.