Declaring a global variable with extern

My problem is in the following context:

file1.h

#include "graphwnd.h"
#include "file2.h"

class XXX: 
{
....various things....
protected:
CGraphWnd graph_wnd_sensor1D;
}  

file1.cpp

#include "file1.h"
(... various stuff ...)

void main(){
OnInitGraph(&graph_wnd_1_sensor2D, rect_1_sensor2D);
graph_wnd_sensor1D.ShowWindow(SW_HIDE);
myYYY.Init();
}
(... various stuff ...)

here graph_wnd_sensor1D matters, and the ShowWindow function

2.h file

extern CGraphWnd graph_wnd_sensor1D;
class YYY: 
{
void YYY::Init(){
graph_wnd_sensor1D.ShowWindow(SW_SHOW);
}
....various things....
}

Here, in init, the application crashes because graph_wnd_sensor1D does not have the same information as the previous one.

In the 2.cpp file, I want to use graph_wnd_sensor1D. But visual lessons

CMyTabCtrl.obj : error LNK2001: external symbol unresolved "class CGraphWnd graph_wnd_sensor1D"
  • So, the idea is to get the value of the variable graph_wnd_sensor1D, which is declared in file1! How can i solve this? *
+3
source share
1 answer

You only declared, but did not define a variable. Add the definition to a single implementation file.

2.h file

extern CGraphWnd graph_wnd_sensor1D; // declarations

2.cpp file

CGraphWnd graph_wnd_sensor1D; // definition
+6
source

All Articles