Originally Posted by
vexon
Here's a more complete code:
Code:
//af editor.h
extern CString currentfile;
struct AFHEADER {
short m_fighternumber;
};
//af editor.cpp
include "af editor.h"
CString currentfile;
extern struct afheader AFHEADER;
//LoadingDlg.cpp
include "af editor.h"
//blah some code etc..
afheader.m_fighternumber = buffer[0];
Code:
//af editor.h
extern CString currentfile;
struct AFHEADER {
short m_fighternumber;
};
//af editor.cpp
include "af editor.h"
CString currentfile;
extern struct AFHEADER afheader;
//LoadingDlg.cpp
include "af editor.h"
//blah some code etc..
afheader.m_fighternumber = buffer[0];
extern isn't a instruction. It's a keyword that tells the linker that the variable is defined in some other object file, so that the linker will use that variable when being refered.
you declare a variable in a file
Code:
//file1.cpp
int zzz = 0;
if you want to use that same variable in another file you declare it as external so the linker will later search for it in another object file.
Code:
//file2.cpp
extern int zzz;