473,791 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cyclic header dependency

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_p tr<struct LatchLatchPtr;

class Latch
{
...
CircuitPtr circuit;
};

circuit.h file

#include "latch.h"
typedef boost::shared_p tr<struct CircuitCircuitP tr;

class Circuit
{
...
list<LatchPtrla tches;
};

As you can see there is a cyclic dependency. To get things to compile,
what I've done is
I've changed the circuit.h file as follows:

new circuit.h file

// defined in latch.h, can't do #include "latch.h" as that will
introduce cyclic dependency
extern typedef boost::shared_p tr<struct LatchLatchPtr;

typedef boost::shared_p tr<struct CircuitCircuitP tr;

class Circuit
{
...
list<LatchPtrla tches;
};

This solves the problem, but I'm wondering if this is the way to fix
such issues. I know C++ has forward declarations but I"m still trying
to figure out how to use them and if they'll solve this. The other
option is to combine the two header files but I would prefer not to do
that.

Is the above fix bad practice? thanks for your time.

Apr 12 '07 #1
3 4991
an update on this problem. i was able to use forward declarations to
fix this but it seems like Latch has to make a call to circuit object
member functions in one of its members:

void Latch::setContr ol(const NodePtr& n)
{
if (!n)
{
CircuitPtr cir = n->getCircuit() ;
if (!cir)
bailOut("Latch: :setControl()", ERROR_INVALID_C IRCUIT);
// TODO: uncomment once circuit has latch support.
cir->addLatch(n, this->shared_from_th is());
}
control = n;
}

so i will need #include "circuit.h" so forward declarations. Similarly
function members in Circuit:: need to call members of Latch:: so i
guess i have to combine the header files? No other way?
thanks

Apr 12 '07 #2
On Apr 12, 4:45 pm, "pallav" <pallavgu...@gm ail.comwrote:
an update on this problem. i was able to use forward declarations to
fix this but it seems like Latch has to make a call to circuit object
member functions in one of its members:

void Latch::setContr ol(const NodePtr& n)
{
if (!n)
{
CircuitPtr cir = n->getCircuit() ;
if (!cir)
bailOut("Latch: :setControl()", ERROR_INVALID_C IRCUIT);
// TODO: uncomment once circuit has latch support.
cir->addLatch(n, this->shared_from_th is());
}
control = n;

}

so i will need #include "circuit.h" so forward declarations. Similarly
function members in Circuit:: need to call members of Latch:: so i
guess i have to combine the header files? No other way?
thanks


I didn't go through the detail of your code. However, I think what you
need in the header file is only a pointer, which does not make it
necessary to include the header file to introduce the name. You can
use forward declaration in header file and include the header file in
the source file.
Apr 12 '07 #3
On Apr 12, 1:45 pm, "pallav" <pallavgu...@gm ail.comwrote:
an update on this problem. i was able to use forward declarations to
fix this but it seems like Latch has to make a call to circuit object
member functions in one of its members:

void Latch::setContr ol(const NodePtr& n)
{
if (!n)
{
CircuitPtr cir = n->getCircuit() ;
if (!cir)
bailOut("Latch: :setControl()", ERROR_INVALID_C IRCUIT);
// TODO: uncomment once circuit has latch support.
cir->addLatch(n, this->shared_from_th is());
}
control = n;

}

so i will need #include "circuit.h" so forward declarations. Similarly
function members in Circuit:: need to call members of Latch:: so i
guess i have to combine the header files? No other way?
thanks
Your .cc or .cpp file will need to #include both for this to work.
But that doesn't mean you need to combine them or that one .h file
needs to #include the other.

Apr 13 '07 #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...
3
2239
by: Dennis Lerche | last post by:
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 ???
8
2880
by: Christian Christmann | last post by:
Hi, I've a problem with including header files. class A requires header file of class B class B requires header file of class C class C requires header file of class A As can be seen the includes are cyclic. Since I'm using
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
2747
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
1736
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
761
by: pallav | last post by:
I have two 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
1773
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:
6
2727
by: scruggsy | last post by:
Hi, got a possibly stupid question. I have 2 header files each containing class definitions along the lines of: // Header1.h #pragma once #include "Header2.h" // for Class2 class ClassA { Class2 m_class1; };
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
9669
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
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
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
5431
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
4110
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
3
2916
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.