compilation problem... WHY?

  • Thread starter Dariusz Plygawko
  • Start date
D

Dariusz Plygawko

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
 
R

red floyd

Dariusz said:
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.
 
A

Artie Gold

red said:
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
 
P

peter.ludikovsky

Dariusz Plygawko said:
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 (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top