473,327 Members | 1,920 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,327 software developers and data experts.

did any body know how to cross include head files?

Such as in a.h, I need put #include "b.h", while in b.h, I need put #include
"a.h", but it does not work! Any alternative way to do it?

Jul 19 '05 #1
2 9338

"George Zhou" <zh****@udel.edu> wrote in message
news:be**********@news.udel.edu...
Such as in a.h, I need put #include "b.h", while in b.h, I need put #include "a.h", but it does not work! Any alternative way to do it?


Include guards.

#ifndef A_H
#define A_H

// this is a.h

#endif

#ifndef B_H
#define B_H

// this is b.h

#endif

Might not be what you need, but its the answer to your question.

john
Jul 19 '05 #2

"George Zhou" <zh****@udel.edu> wrote in message
news:be**********@news.udel.edu...
Such as in a.h, I need put #include "b.h", while in b.h, I need put #include "a.h", but it does not work! Any alternative way to do it?


I've had this problem before. Something like this:

// a.h
#include "b.h"
class A
{
public:
A();
A(B& data);
int var;
};
// b.h
#include "a.h"
class B
{
public:
B();
B(A& data);
int var;
};

As you can see, both classes need each other's files. You cannot do this,
either you'll be using an endless loop or you'll be smart and use what John
told you to do. Either way, however, one of the files isn't going to have
access to the other's data. So what you need to do is declare, but not
define the information:

// a.h
class B; // declaration

class A
{
public:
A();
A(B& data);
int var;
};

// b.h
#include "a.h"

class B
{
public:
B();
B(A& data);
int var;
};

This will work. I always put a

#pragma once

in my header files, but not all compilers support that. They function
exactly the same way as what John told you to do, it's just less coding.
It's a good idea, it'll protect you from including files more than once (and
then getting a billion redefinition errors).

--
MiniDisc_2k2
To reply, replace nospam.com with cox dot net.

Jul 19 '05 #3

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

Similar topics

2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
23
by: Big Bill | last post by:
http://www.promcars.co.uk/pages/bonnie.php I don't believe they should be there, can I take them out without stopping the includes from functioning? I'm the (hapless) optimiser on this one... I...
21
by: Chen ShuSheng | last post by:
Hey, In head file 'stdio.h', I only find the prototype of these two function but no body. Could someone pls tell me where their bodies are ? -------------- Life is magical.
6
by: Shawn | last post by:
Hello: I have the following code in a PHP file. An HTML form passes user comment data to the PHP, which then appends the user comments to the end of the HTML file on which the form is located....
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
3
by: Sunny | last post by:
Hi, Can someone tell me, How to load the Body Html from a text file that contains javascript. to Manage my files I am creating an Index Page. <html> <head> <meta http-equiv="content-type"...
2
by: urbanedge | last post by:
I've just acquired a site and uploaded to godaddy and the email function won't work. I'm new to php and I'm not able to determine where the issue is. I've commented out $this->header .=...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.