Connecting Tech Pros Worldwide Forums | Help | Site Map

C++ circular references

Newbie
 
Join Date: Jul 2007
Posts: 22
#1: Sep 26 '07
I've three classes: A, B, C

Now class A includes B.h
class B includes A.h
and class C includes both

my problem is that when i try to compile class A, B or C using (g++ -c A.cpp)
it shows errors about variables which are defined in other included classes.
it says B not declared, C not declared.

None of the class has any errors. I can't post the code bcoz its quite lengthy.

Please help me resolving the issue.
Thanks in advance

ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 389
#2: Sep 26 '07

re: C++ circular references


I am not getting your question.
how can class include the .h files?
are there three separate .cpp files like A.cpp B.cpp & C.cpp including those classes respectively?
Savage's Avatar
Expert
 
Join Date: Feb 2007
Posts: 1,737
#3: Sep 26 '07

re: C++ circular references


Make forward declarations of the classes:

In A add for B,and vise versa.

Savage
Reply