在Struct中使用Static时出错

Error when using Static in Struct

本文关键字:Static 出错 Struct      更新时间:2023-10-16

好了,我很累了否则我会深入查找这个问题(我的意思是我有一点,但没有找到我想要的)

我试图使我的结构中的所有变量都是静态的,因为它需要保持所有的值在另一个函数中求值。

(我将只发布相关的代码片段)这是我的代码,希望你能告诉我这是怎么回事:

错误:未解析的外部符号"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];