Jan 25, 2009 at 9:31pm UTC
Hy guys,
I have a struct defined in one file:
struct.cpp
#include <stdio.h>
#include <stdio.h>
typedef struct _ZONA
{
int preco;
int numero;
int numLugaresVendidos;
int numLugares;
}ZONA;
ZONA _zona1;
ZONA _zona2;
How do i declare the _zona1 and _zona2 in other files to work with the same variables?
I know if i use a var like this:
int var;
to use in other file i do:
extern int var;
but i tried using:
extern ZONA _zona1;
but it give errors.
Thanks,
Daniel Gomes
Jan 25, 2009 at 9:40pm UTC
You should declare the struct in a header file. Then include that header file within source files you want to use.
If you want to use the same instance, then you can use the extern keyword.
Jan 25, 2009 at 9:44pm UTC
Thanks for your reply Zaita.
Zaita, can you show me a little example how to create the header file? I don't know how to create it.
Thanks,
Daniel Gomes
Jan 25, 2009 at 10:02pm UTC
Thanks Zaita, it works fine :)