在Struct中使用Static时出错
Error when using Static in Struct
好了,我很累了否则我会深入查找这个问题(我的意思是我有一点,但没有找到我想要的)
我试图使我的结构中的所有变量都是静态的,因为它需要保持所有的值在另一个函数中求值。
(我将只发布相关的代码片段)这是我的代码,希望你能告诉我这是怎么回事:
错误:未解析的外部符号"public: static wchar_t * gamellaunch::directory"
未解析的外部符号"public: static wchar_t * gameLaunch::AppName"
未解析的外部符号"public: static wchar_t * gameLaunch::ComboBoxName"
struct gameLaunch
{
int ID = 0;
static wchar_t directory[MAX_PATH];
static wchar_t AppName[MAX_PATH];
static wchar_t ComboBoxName[MAX_PATH];
}gameLaunchtest;
gameLaunch test[100];
gameLaunch gameLaunchtest;
case IDB_CLICK_ME:
{
GetWindowText(hProgramDirectory, gameLaunchtest.directory, MAX_PATH);
GetWindowText(hProgramName, gameLaunchtest.AppName, MAX_PATH);
GetWindowText(hProgramNameComboBox, gameLaunchtest.ComboBoxName, MAX_PATH);
wofstream launchLocations;
launchLocations.open("LaunchLocations.txt", std::ios_base::app | std::ios_base::out);
launchLocations << gameLaunchtest.directory << endl;
launchLocations << gameLaunchtest.AppName << endl;
launchLocations << gameLaunchtest.ComboBoxName << endl;
ComboBox_AddString(comboBox, gameLaunchtest.directory);
launchLocations.close();
break;
case IDB_CLICK_ME_AGAIN:
int selectedNumber = 0;
while (true)
{
selectedNumber = ComboBox_GetCurSel(comboBox);
if (test[number].ID = selectedNumber)
{
ShellExecute(NULL, L"open", test[number].AppName, NULL, test[number].directory, 5);
}
number = number + 1;
}
break;
您需要在类/结构之外声明静态字段。应该按以下方式完成:
wchar_t gameLaunch::directory[MAXPATH];
wchar_t gameLaunch::AppName[MAXPATH];
wchar_t gameLaunch::ComboBoxName[MAXPATH];
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 在Struct中使用Static时出错