473,804 Members | 3,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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
Jul 22 '05 #1
3 2240

"Dennis Lerche" <dl****@control .auc.dk> wrote in message
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


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.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
Jul 22 '05 #4

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

Similar topics

7
2784
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 project 1-solution A accessing a "save" method in project 2-solution B as well as "getinfo" method in project 2 accessing a "read" method in project A. Is this permitted? I am getting the "dependency file in project cannot be copied... conflict...
0
1418
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 stored procedure updates a row in C, adds a row each in B & C. I get an integrity violation. All the foreign keys are deferrable, and the stored procedure is called from within a transaction with constraints deferred. (And the foreign keys do refer to...
4
4553
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 may do that? Alex.
3
2124
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 this apply to the condition when there is a cyclic reference for the binaries (dlls) in dotNet !! What I am thinking is that to use the real ProjectB object I will still need
3
2750
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 inclusion relationships. Another question I have is how to solve this dependency when "typedef" is used. usually we can use forward declaration like "struc A; " to solve references like "struct A* p". But in many places we have
4
1737
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 the sort, we have a way around this. I am simply trying to understand the order or creation and the reason for the call to the COuterClass copy constructor. Any help would be seriously appreciated. Thanks in advance. class COuterClass;
1
677
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; class Latch {
3
1774
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
3231
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
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.