我正在使用visual C++ 2010。这个问题让我困惑了很长时间。我可以在 *.cpp 中定义一个数组:
wstring pairs[][2] =
{
{L"\\ben\\b", L"English"},
{L"\\bfr\\b", L"French"},
{L"\\bit\\b", L"Italian"},
{L"\\bde\\b", L"German"},
{L"\\bes\\b", L"Spanish"},
{L"\\bpl\\b", L"Polish"},
{L"\\bru\\b", L"Russian"},
{L"\\bzh_cn\\b", L"ChinesePRC"},
{L"\\bzh_tw\\b", L"ChineseTaiwan"},
{L"\\bja\\b", L"Japanese"},
{L"\\bko\\b", L"Korean"},
{L"\\bpt\\b", L"PortugueseStandard"},
{L"\\btr\\b", L"Turkish"},
{L"\\bnl\\b", L"Dutch"},
{L"\\blt\\b", L"Lithuanian"},
{L"\\blv\\b", L"Latvian"},
{L"\\bet\\b", L"Estonian"}
};
并像这样在 *.h 中声明数组:
extern wstring pairs[][2];
现在我可以在其他 *.cpp 中使用该数组,但我无法获得pairs
使用代码的大小:
size_t cnt = _countof(pairs);
我收到错误消息:
1>e:\work\vc++\justtest\console\console.cpp(45): error C2893: Failed to specialize function template 'char (*__countof_helper(_CountofType (&)[_SizeOfArray]))[_SizeOfArray]'
1> With the following template arguments:
1> 'std::wstring [2]'
我很困惑是否可以像这样使用数组?有人可以帮助我吗?