473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cyclic Dependency problem


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(foo1 *temp){
foo1->calcSomething(); //function call to the object foo1
}

foo::anotherCall(){}

foo1.h
-----
#include foo.h

class foo1{
public:
calcSomething();
anotherFunction();

}

foo1.cpp
-------

foo1::calcSomething(foo *temp){
}

foo1::anotherFunction(){
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
Jul 22 '05 #1
3 2215

"Dennis Lerche" <dl****@control.auc.dk> wrote in message
news:yv**************@dupond.control.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(foo1 *temp){
foo1->calcSomething(); //function call to the object foo1
}

foo::anotherCall(){}

foo1.h
-----
#include foo.h

class foo1{
public:
calcSomething();
anotherFunction();

}

foo1.cpp
-------

foo1::calcSomething(foo *temp){
}

foo1::anotherFunction(){
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


Merge the two header files (when you have cyclic dependencies you should
usually do this, and I don't think a cyclic dependencies automatically means
bad design).

Like this

// combined foo header file
class foo1;

class foo{
public:
funcCalc(foo1 *temp);
anotherCall();
};

class foo1{
public:
calcSomething();
anotherFunction();
};

Any inline function calls can go after foo and foo1 within the header file.

john
Jul 22 '05 #2
"John Harrison" <jo*************@hotmail.com> writes:

Any inline function calls can go after foo and foo1 within the header file.

john


Thanks

That works :o)

Dennis
Jul 22 '05 #3

Uzytkownik "Dennis Lerche" <dl****@control.auc.dk> napisal w wiadomosci
news:yv**************@dupond.control.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(foo1 *temp){
foo1->calcSomething(); //function call to the object foo1
}

foo::anotherCall(){}

foo1.h
-----
#include foo.h

class foo1{
public:
calcSomething();
anotherFunction();

}

foo1.cpp
-------

foo1::calcSomething(foo *temp){
}

foo1::anotherFunction(){
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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Brian Sabolik | last post by:
I'm not sure if I've broken any Object Oriented rules or not, but ... I have projects in 2 different solutions that need to use each other's methods. Therefore I may have an "update" method in...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
4
by: Alex Sedow | last post by:
For example, System.dll contains assembly reference to System.XML.dll, System.XML.dll refers to System.dll. Some another open projects contain cyclic assembly dependencies too. How C# compiler...
3
by: Pohihihi | last post by:
This is a report from VSS newsgroup in hope of getting some more suggestions. Thanks, Po ------------------------------------------- I guess I am not getting the whole picture here. How does...
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
4
by: sakis.panou | last post by:
Hi all, Can anyone explain to me why the copy constructor of the COuterClass is getting called for this one? Let me start by saying I reckon this is seriously bad way of implementing anything of...
1
by: pallav | last post by:
I have to header files, circuit.h and latch.h that reference each other and are causing a cyclic dependency. latch.h file #include "circuit.h" typedef boost::shared_ptr<struct LatchLatchPtr;...
3
by: soup007 | last post by:
Hi, I am having some difficulties with cyclic dependency between two classes. Situation is something like following - ///A.h #include "B.h" class A { { int X; public:
11
by: sgurukrupagmailcom | last post by:
Hi, When searching for a solution to my problem I stumbled upon 'Curiously Recurring Template Pattern' see link. This is how the pattern looks: template < typename T > struct y { } ;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.