Re: header file help......
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 03 Jul 2007 08:17:16 -0400
Define "use". Do you mean "Can I declare objects of the type declared in the first header
file in the second?" and the answer is "yes". If the question is "can I use the name as
the name of a structure in another header file" and the answer is "if the two files are
never included in the same compilation unit, yes, but this would be an Exceptionally Bad
Idea"
Consider a.h
typedef struct {
....stuff here
} A, *PA;
consider b.h
typedef struct {
A a1;
A a2;
} B, *PB;
this is valid but only if a.h has already been included. Therefore, two things need to be
added:
in a.h, add the line
#pragma once
so that multiple includes will not generate errors of multiply-defined symbols. In b.h it
is necessary to write
#include "a.h"
before the usage. The general rule is that every header file ought to have
#pragma once
in it, so b.h really should have that line added also. And every header file should
explicitly include everything it needs for correct compilation. So a file
c.h:
#pragma once
#incldue "a.h"
typedef struct {
A a1;
A a2;
} C, *PC;
Now, if your program app.cpp has
#include "stdafx.h"
#include "b.h"
#incldue "c.h"
it will compile correctly because a.h is already included by BOTH b.h and c.h, but because
of the #pragma once it is actually read only once. Note that if you invert the order to
be
#include "c.h"
#incldue "b.h"
then it wil STILL compile correctly because a.h is still included independent of the
order.
joe
On Mon, 02 Jul 2007 23:47:22 -0700, raju2000myin@xxxxxxxxx wrote:
Joseph M. Newcomer [MVP]
am delare one structure in one header file.........
can i use that structure name in another header file......... is it
possible.
If yes how can i use that..........
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- header file help......
- From: raju2000myin
- header file help......
- Prev by Date: Re: WaitForSingleObject() will not deadlock
- Next by Date: Re: An easy way to Read and Write to SQL Server using MFC???
- Previous by thread: Re: header file help......
- Next by thread: great ng
- Index(es):
Relevant Pages
|
|