|
I am using VC to make a single document project proj.
Contains files such as mainfrm.cpp; proj.cpp; projDoc.cpp; projView.cpp.
A header file defining global variables is included in the project: "globlevariable.h"
The structure is defined in the above header file and the corresponding global variables are declared:
///
.....
struct g_sCtrldata
{
struct g_sCtrldata * pNext;
struct g_sCtrldata * head;
double x;
double y;
double dy;
double ddy;
}; // Structure definition
g_sCtrldata * g_ContrldataHipA; // Global variable declaration
.....
//
Then I include this header file in Mainfrm.cpp and assign a value to the global variable * g_ContrldataHipA.
Mainfrm.cpp:
///
#include "globlevariable.h"
g_ContrldataHipA = (g_sCtrldata *) malloc (sizeof (g_sCtrldata) * 100);
.....
for (int i = 0; i <100; i ++)
{(g_ContrldataHipA + i)-> pNext = pI + 1;
(g_ContrldataHipA + i)-> x = * (g_dOutX + i);
(g_ContrldataHipA + i)-> y = * (g_dOutY + i);
(g_ContrldataHipA + i)-> dy = * (g_dOutDY + i);
(g_ContrldataHipA + i)-> ddy = * (g_dOutDDY + i);
(g_ContrldataHipA + i)-> head = g_ContrldataHipA;
Ranch
}
...
All the above went well.
But when I want to display the values in the g_ContrldataHipA array with a curve, I need to access and modify it in projView.cpp. Then the problem came out:
When using g_ContrldataHipA, an error is displayed during compilation, and g_ContrldataHipA is not defined.
I also use extern g_ContrldataHipA.
But other non-structural global variables in globalvariable.h can be used directly, such as double precision variables, integer variables, and so on.
Later I thought of adding #include "globlevariable.h" to projView.cpp
But this time prompted hundreds of errors, because "globlevariable.h" is already defined in main.obj. : Error LNK2015: "struct g_sCtrldata * g_Contrldata" (? G_Contrldata @@ 3PAUg_sCtrldata @@ A) already defined in MainFrm.obj
Please masters to help me solve this problem, is it not possible to pass the structure as a global variable in different classes? |
|