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

how to avoid using another header file inside a header file?

I have a library function like GetOptions( ..., struct net_arch_t netArch,
....) and put the declaration into a regular header file like getopt.h. But
this function declaration also needs the declaration of struct net_arch_t
which is located in another header file, e.g., nn.h. I saw somewhere that it
should be avoided to include another header file inside one header file. So
I am trying to use some other methods.

One option is for each source file that needs the GetOption function,
include both the getopt.h and nn.h and place nn.h ahead of the getopt.h. But
isn't it awkard? Is there any better way to do it? It happens some often to
me. Thanks.

Ann
Jul 19 '05 #1
4 3903
Newsgroup - Ann wrote:
I have a library function like GetOptions( ..., struct net_arch_t netArch,
...) and put the declaration into a regular header file like getopt.h. But
this function declaration also needs the declaration of struct net_arch_t
which is located in another header file, e.g., nn.h. I saw somewhere that it
should be avoided to include another header file inside one header file. So
I am trying to use some other methods.
A header should always #include whatever it needs. Perhaps there was
some specific context in which this suggestion was made?

One option is for each source file that needs the GetOption function,
include both the getopt.h and nn.h and place nn.h ahead of the getopt.h. But
isn't it awkard? Is there any better way to do it? It happens some often to
me. Thanks.

See above.

HTH,
--ag


--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 19 '05 #2
Newsgroup - Ann wrote:
I have a library function like GetOptions( ..., struct net_arch_t netArch,
...) and put the declaration into a regular header file like getopt.h. But
this function declaration also needs the declaration of struct net_arch_t
which is located in another header file, e.g., nn.h. I saw somewhere that it should be avoided to include another header file inside one header file. So I am trying to use some other methods.

One option is for each source file that needs the GetOption function,
include both the getopt.h and nn.h and place nn.h ahead of the getopt.h. But isn't it awkard? Is there any better way to do it? It happens some often to me. Thanks.


Forward declare:

struct net_arch_t;

GetOptions(int argc, char **argv, net_arch_t & arch);

--
Phlip
Jul 19 '05 #3
Hi,

"Newsgroup - Ann" <ne******@yahoo.com> wrote in message
news:3f**********@rcfnews.cs.umass.edu...
I have a library function like GetOptions( ..., struct net_arch_t netArch,
...) and put the declaration into a regular header file like getopt.h. But
this function declaration also needs the declaration of struct net_arch_t
which is located in another header file, e.g., nn.h. I saw somewhere that it should be avoided to include another header file inside one header file. So I am trying to use some other methods.
No. You should include all header files that are needed. Otherwise someone
using your module has to understand he not only has to include the header
file of your module (which is opvious) but he also has to figure out what
are header files should be included to make it work.

Regards, Ron AF Greve.


One option is for each source file that needs the GetOption function,
include both the getopt.h and nn.h and place nn.h ahead of the getopt.h. But isn't it awkard? Is there any better way to do it? It happens some often to me. Thanks.

Ann

Jul 19 '05 #4
Newsgroup - Ann wrote:
I have a library function like GetOptions( ..., struct net_arch_t netArch,
...) and put the declaration into a regular header file like getopt.h. But
this function declaration also needs the declaration of struct net_arch_t
which is located in another header file, e.g., nn.h. I saw somewhere that it
should be avoided to include another header file inside one header file. So
I am trying to use some other methods.

One option is for each source file that needs the GetOption function,
include both the getopt.h and nn.h and place nn.h ahead of the getopt.h. But
isn't it awkard? Is there any better way to do it? It happens some often to
me. Thanks.


You can use forward declarations like:

class myClass;
struct someStruct;

but this only works if all the usages of myClass and
someStruct in the header are via references or pointers. In
the example you give of GetOptions netArch is being passed
by value so that definition at least will have to any source
code that calls the function. Some compilers will let you
get away with just the forward declaration of struct
net_arch_t in the header others will not.

In general you should keep includes to a minimum in header
files, include only those headers you need and no more. One
recommendation is that the first include in classA.cpp
should be classA.h this will ensure that classA.h is complete.

What you shouldn't do is put any additional includes into
classA.h that are required internally by classA.cpp. Example
classA::sort() uses classX internally, but there is no usage
of classX in the classA interface, do not include classX in
classA.h but in classA.cpp.

Jul 19 '05 #5

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

Similar topics

2
by: trying_to_learn | last post by:
im in the primary stages of learning C++. The book im learning from says Dont use using namespace.. directive in header file However im trying to make the following header file.I need to include...
3
by: AK | last post by:
I'm using a .NET Windows Forms Applications project. I'm using LoadLibrary & GetProcAddress to use a DLL function. This is all done in the main cpp file. I would like to use this DLL function in a...
24
by: ypjofficial | last post by:
Hello all, I have written a class with many private data members.and i am putting it in a separate dll file. Now when i link that file while writing my main program module,natuarally i have to...
3
by: Paul F. Johnson | last post by:
Hi, I'm trying to create a zip file from some pdfs and have code similar to this $id=$_GET; $fn = array("a", "b", "c", "d"); chdir('../downloads'); // the php file is in /php $files =...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
18
by: StephQ | last post by:
I'm facing the following problem: I'm using the Gnu Scientific Library (it is a C math library), and in particular random number generation algorithms. Example code is: .... gsl_rng * r; .......
3
by: =?Utf-8?B?QW5keQ==?= | last post by:
Hello, I'm trying to use a string type variable inside a class. I can do this fine with no problems when the class is inside a cpp file simply by adding #include <string>. However, my program has...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
8
by: benn | last post by:
Here's the setup... Defines.h file contains: enum DAY { monday, tueday }; DayFunctions.h contains prototype: void printIsMonday ( enum DAY currentDay); DayFunctions.c contains:
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

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.