Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to prevent circular #include

Reply
Thread Tools

How to prevent circular #include

 
 
junw2000@gmail.com
Guest
Posts: n/a
 
      01-19-2007
In the example below:

------------------------------
f1.h

#include "f2.h"

class A1{

void g();
}

class A2{}

--------------------------------
f1.cpp

#include "f1.h"

void A1::g(){

B1 b;
B1::h();
}

---------------------------------
f2.h

#include "f1.h"
class B1{
static void h();
}
--------------------------------
f2.cpp

#include "f2.h"
void B1::h(){
A2 a;

}

How to solve this problem other than merging f1.h and f2.h?

Thanks.

Jack

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-19-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> How to solve this problem other than merging f1.h and f2.h?
>

Through a combination of include guards in the headers and forward
declarations.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
hit_pc
Guest
Posts: n/a
 
      01-19-2007
On Fri, 19 Jan 2007 16:08:56 +0800, <(E-Mail Removed)> wrote:

> In the example below:
>
> ------------------------------
> f1.h
>
> #include "f2.h"
>
> class A1{
>
> void g();
> }
>
> class A2{}
>
> --------------------------------
> f1.cpp
>
> #include "f1.h"
>
> void A1::g(){
>
> B1 b;
> B1::h();
> }
>
> ---------------------------------
> f2.h
>
> #include "f1.h"
> class B1{
> static void h();
> }
> --------------------------------
> f2.cpp
>
> #include "f2.h"
> void B1::h(){
> A2 a;
>
> }
>
> How to solve this problem other than merging f1.h and f2.h?
>
> Thanks.
>
> Jack
>

#ifndef F2_H
#define F2_H
blablabla
……
#endif /*F2_H*/


--
Hello,World!
----legolaskiss.
 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      01-19-2007
(E-Mail Removed) wrote:

> In the example below:

This is C-language question

a) remove "#include"s from "*.h"
b) if can not remove, use "#ifndef/define" in each "*.h"

/*
LIBNAME is your libname
FILE_NAME is current "*.h" file name
*/

#ifndef LIBNAME##_##FILE_NAME
#define LIBNAME##_##FILE_NAME

> #include "f2.h"
>
> class A1{
>
> void g();
> }
>
> class A2{}
>


#endif

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Semi-circular definitions (plus circular references) Kiuhnm C++ 16 01-03-2005 03:49 AM
Circular References in Visual Studio =?Utf-8?B?S2VpdGggRi4=?= ASP .Net 3 08-06-2004 04:42 PM
Re: Circular References Bill Jones ASP .Net 1 04-08-2004 10:16 PM
Circular references are not supported Dan C Douglas ASP .Net 1 08-13-2003 09:21 PM



Advertisments