i wanna put all my variable initialization at a header file..
but after i put in a header file name, "variable.h"

i #include "variable.h" in main. but it still cant reconize the variable.
what can i do? + extern infront all the variable in header file?

8 Years
Discussion Span
Last Post by Ancient Dragon

you don't initialize variables in header files becuse the variables don't exist. You have to declare variables in *.c or *.cpp files. You can, however, use the extern keyword with variable in header files, but again they can not be initialized there.

// myheader.h file
extern int myint;

Then in one, and only one, *.cpp file you declare the same variable but without extern keyword. You can also initialize it then.

// myprogram.cpp
#include "myheader.h"

int myint = 0;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.