struct question

Hi guys,
I have a struct defined in a header, is it possible to use the same struct variable across more than one file. in other words like this....

header.h
1
2
3
4
5
struct box
{
    int length;
    int width;
}


file1.cpp
 
box.abox


file2.cpp
 
box.abox
yes you can by putting extern keyword ....
in each file i use it in? or just in the header?
in the file where you are using the box .
when i put an extern keyword in front of each variable definition it get an unresolved symbols error
can you post your code
header.h should include the struct definition.
struct box {
int length;
int width;
};

in file1.c
#include "header.h"

struct box abox; /* abox is variable of type struct box*/

do whatever you can do with that.

in file2.c
#include "header.h" /* verify it do we really need it here */
extern struct box abox;

use abox here

i hope this will solve your problem.
Regards
In C++ you don't need to say struct box abox; to instantiate a struct or class. They behave just like built-in data types, so you should just say box abox; instead.
ok ive got a betrer idea now, i had already used a struct in another program that had the struct in a header and the variable in the file, my main question was about
using 2 files but thanks for your replies
Topic archived. No new replies allowed.