// 一个基于单文档的程序CMainFrame.CPP中IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};// 问题一:
// indicators是一个CMainFrame.CPP域的全局变量,这样理解正确吗?// 问题二:
// 如果将其static屏蔽,并没有什么影响?那么加关键字static是出于什么考量呢?// 问题三:
// 如果将static UINT indicators[] = {...}从CMainFrame.CPP移至CMainFrame.h中
// static存在,运行OK.
// static屏蔽,报以下错,为什么呢?
// 1>Linking...
// 1>MainFrm.obj : error LNK2005: "unsigned int * indicators" (?indicators@@3PAIA) already defined in tmp.obj
// 1>F:\PROJECT FOR VS2008\tmp\Debug\tmp.exe : fatal error LNK1169: one or more multiply defined symbols found// 问题四:
// 如果用const代替static,并没有什么影响。但是日后indicators[2] = ID_INDICATOR_CAPS报错。不用const,是为了它的允许变更。
// 这样理解正确吗?
ON_WM_CREATE()
END_MESSAGE_MAP()static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};// 问题一:
// indicators是一个CMainFrame.CPP域的全局变量,这样理解正确吗?// 问题二:
// 如果将其static屏蔽,并没有什么影响?那么加关键字static是出于什么考量呢?// 问题三:
// 如果将static UINT indicators[] = {...}从CMainFrame.CPP移至CMainFrame.h中
// static存在,运行OK.
// static屏蔽,报以下错,为什么呢?
// 1>Linking...
// 1>MainFrm.obj : error LNK2005: "unsigned int * indicators" (?indicators@@3PAIA) already defined in tmp.obj
// 1>F:\PROJECT FOR VS2008\tmp\Debug\tmp.exe : fatal error LNK1169: one or more multiply defined symbols found// 问题四:
// 如果用const代替static,并没有什么影响。但是日后indicators[2] = ID_INDICATOR_CAPS报错。不用const,是为了它的允许变更。
// 这样理解正确吗?
// indicators是一个CMainFrame.CPP域的全局变量,这样理解正确吗? 是的// 问题二:
// 如果将其static屏蔽,并没有什么影响?那么加关键字static是出于什么考量呢? 将indicators变量限制在MainFrame.cpp中,其他编译单元看不到该变量名// 问题三:
// 如果将static UINT indicators[] = {...}从CMainFrame.CPP移至CMainFrame.h中
// static存在,运行OK.
// static屏蔽,报以下错,为什么呢?
// 1>Linking...
// 1>MainFrm.obj : error LNK2005: "unsigned int * indicators" (?indicators@@3PAIA) already defined in tmp.obj
// 1>F:\PROJECT FOR VS2008\tmp\Debug\tmp.exe : fatal error LNK1169: one or more multiply defined symbols found 可见范围发生了变化,跟其他代码的配合产生了副作用(side effect).// 问题四:
// 如果用const代替static,并没有什么影响。但是日后indicators[2] = ID_INDICATOR_CAPS报错。不用const,是为了它的允许变更。
// 这样理解正确吗?
是的