Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Structure...

Status
Not open for further replies.

MarkLaz

Technical User
May 20, 2005
12
GB
Hello all,

Can I put a structure in a header file (as in, for use in main body of code, but to keep things tidy)?

Cheers....
 
It's an ambiguous question.
You may place a structure declaration, but not a structure definition.
For example:
Code:
// header example.h:
struct S { ... }; // or
typedef struct { ... } S; 
// cpp files:
#include "example.h"
S s; // Global structure variable in 1 file only
// in others:
extern S s;
You may add in the header (after S declaration):
Code:
extern S s;
then write in one of (and the only) files s var definition:
Code:
S s;
If you have in the header
Code:
struct S { ... } s;
- you have not-unique s definitions in cpp files with #include "example.h".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top