我要在2个对话框中访问同一个结构数组,所以,我就想用全局数组,但我不知道如何定义,在Stdafx中定义,编译器总是提示我重复
error LNK2005: "struct tables_ex * tables_ex" (?tables_ex@@3PAU0@A) already defined in StdAfx.obj在Stdafx总,我是这样写的~
struct tables_ex tables_ex[27];然后,我发现赋值也是一个问题..其实我想最好的方法是能定义的时候就能赋值,就像这样struct tables_ex
{
int nIndex;
TCHAR * szTable;
BOOL bChecked;
}
tables_ex[] =
{
1,TEXT("Something"),TRUE,
2,TEXT("Something"),TRUE,
};
我应该在哪里定义才是比较合适的,2个对话框都是不同的.h和.cpp文件..
error LNK2005: "struct tables_ex * tables_ex" (?tables_ex@@3PAU0@A) already defined in StdAfx.obj在Stdafx总,我是这样写的~
struct tables_ex tables_ex[27];然后,我发现赋值也是一个问题..其实我想最好的方法是能定义的时候就能赋值,就像这样struct tables_ex
{
int nIndex;
TCHAR * szTable;
BOOL bChecked;
}
tables_ex[] =
{
1,TEXT("Something"),TRUE,
2,TEXT("Something"),TRUE,
};
我应该在哪里定义才是比较合适的,2个对话框都是不同的.h和.cpp文件..
变量和函数有申明和定义之分.
申明是只说明数据类型如 struct tables_ex tables_ex[];
定义既说明数据类型又分配存储空间如struct tables_ex tables_ex[27];
他们的区别是有没有分配存储空间。
你在 stdafx.h 中定义,如果每个cpp 都包含了它,那么有多少个cpp,
变量就被定义了多少遍,当然会出连接错误啦。这样写吧
stdafx.h: extern struct tables_ex tables_ex[];
任意一个cpp中 struct tables_ex tables_ex[27] = {...};