Uzytkownik "Dennis Lerche" <dl****@control .auc.dk> napisal w wiadomosci
news:yv******** ******@dupond.c ontrol.auc.dk.. .
Hi
I have a problem regarding cyclic dependency, yeahh I know bad
design. But right at this moment I can't see how it should be
redesigned to avoid this. The problem is that I just can't get it to
compile .....
I have two classes each having their own header files, including each
other. A forward decleration doesn't seem to be enough because they
also call function calls within the classes. How do I solve this ???
Example:
foo.h
-----
#include foo1.h
class foo{
public:
funcCalc(foo1 *temp);
anotherCall();
}
foo.cpp
-------
foo::funcCalc(f oo1 *temp){
foo1->calcSomething( ); //function call to the object foo1
}
foo::anotherCal l(){}
foo1.h
-----
#include foo.h
class foo1{
public:
calcSomething() ;
anotherFunction ();
}
foo1.cpp
-------
foo1::calcSomet hing(foo *temp){
}
foo1::anotherFu nction(){
foo->anotherCall( ); //function call to the object foo1
}
This is just a very simple example of the mess I'm dealing with. How
do I solve this ??
--
Dennis
From your files I do not see why foo.h should include foo1.h?
Foo.h only declares a member function that takes pointer to foo1. For this
to compile you only need a forward delaration of foo1. Because you say that
fwd declaration is not sufficient, you probably call foo1 member functions
in foo.h, but this is not in the sample files that you supplied.
To resolve that perhaps it's enough to move definitions of all functions
that use foo1 from foo.h into foo.cpp. There you can safely include anything
you want. What you lose is inlining of such functions, unless your compiler
supports cross-module inlining.
regards,
Marcin