HEADER FILE PROBLEM
-
I've two global variables which I require defined in a header file, unfortunately I require this file to be included in more than one C++ file. However I get an error in relation to the global variables being defined twice. Any suggestions on a workaround? Kind Regards Caoimh
-
I've two global variables which I require defined in a header file, unfortunately I require this file to be included in more than one C++ file. However I get an error in relation to the global variables being defined twice. Any suggestions on a workaround? Kind Regards Caoimh
-
I've two global variables which I require defined in a header file, unfortunately I require this file to be included in more than one C++ file. However I get an error in relation to the global variables being defined twice. Any suggestions on a workaround? Kind Regards Caoimh
u forgot to type "extern" some.h int gGlobal; fx.c extern int gGlobal;
-
I've two global variables which I require defined in a header file, unfortunately I require this file to be included in more than one C++ file. However I get an error in relation to the global variables being defined twice. Any suggestions on a workaround? Kind Regards Caoimh
We normally dont define a variable in the header file as the header file is included in many cpp files, it causes redefination of the variable. Instead we define the variable in a .cpp file or .c file and an extern in the .h file. In windows application developed using the project wizard, it creates two files namely stdafx.h and stdafx.cpp stdafx is by default included in each file that you add using the classwizard. and stdafx.cpp is generally a empty file except for #include "stdafx.h" So the best thing is to put the defination of the variable in the stdafx.cpp file and extern in stdafx.h file forexample in stdafx.cpp file
#include "stdafx.h"
int g_SomeGlobalVariable;and in stdafx.h file
extern int g_SomeGlobalVariable;
hope this solves ur problem.
1.Why do people not wearing a wrist watch look at their wrist for time when people ask for time. 2.Why do people ask for time from people who are not wearing a wrist watch. Prakash, India.
-
We normally dont define a variable in the header file as the header file is included in many cpp files, it causes redefination of the variable. Instead we define the variable in a .cpp file or .c file and an extern in the .h file. In windows application developed using the project wizard, it creates two files namely stdafx.h and stdafx.cpp stdafx is by default included in each file that you add using the classwizard. and stdafx.cpp is generally a empty file except for #include "stdafx.h" So the best thing is to put the defination of the variable in the stdafx.cpp file and extern in stdafx.h file forexample in stdafx.cpp file
#include "stdafx.h"
int g_SomeGlobalVariable;and in stdafx.h file
extern int g_SomeGlobalVariable;
hope this solves ur problem.
1.Why do people not wearing a wrist watch look at their wrist for time when people ask for time. 2.Why do people ask for time from people who are not wearing a wrist watch. Prakash, India.