Hi everyone! At the moment I’m developing the settings menu of the game and encountered a problem that I do not know how to solve and would like to ask for your help.
Here are the errors I encountered:
0>SettingsMenu.cpp(55): Error C2429 : language feature 'structured bindings' requires compiler flag '/std:c++17'
0>SettingsMenu.cpp(57): Error C2672 : 'std::invoke': no matching overloaded function found
0>type_traits(1709): Reference C2672 : could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
0>SettingsMenu.cpp(57): Reference C2672 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
0>SettingsMenu.cpp(57): Reference C2672 : With the following template arguments:
0>SettingsMenu.cpp(57): Reference C2672 : '_Callable=unknown-type &'
0>SettingsMenu.cpp(57): Reference C2672 : '_Ty1=UGameUserSettings *&'
0>SettingsMenu.cpp(57): Reference C2672 : '_Types2={}'
0>type_traits(1712): Reference C2672 : 'std::_Invoker1': too few template arguments
0>type_traits(1680): Reference C2672 : see declaration of 'std::_Invoker1'
0>type_traits(1712): Reference C2672 : '<missingId>': identifier not found
0>type_traits(1703): Reference C2672 : or 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
0>SettingsMenu.cpp(57): Reference C2672 : 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 2 provided
0>SettingsMenu.cpp(57): Error C2737 : 'CurrentSelection': const object must be initialized
0>SettingsMenu.cpp(58): Error C3536 : 'CurrentSelection': cannot be used before it is initialized
0>SettingsMenu.cpp(61): Error C2672 : 'std::invoke': no matching overloaded function found
0>type_traits(1709): Reference C2672 : could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
0>SettingsMenu.cpp(61): Reference C2672 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept(<expr>)'
0>SettingsMenu.cpp(61): Reference C2672 : With the following template arguments:
0>SettingsMenu.cpp(61): Reference C2672 : '_Callable=const unknown-type &'
0>SettingsMenu.cpp(61): Reference C2672 : '_Ty1=UGameUserSettings *&'
0>SettingsMenu.cpp(61): Reference C2672 : '_Types2={int &}'
0>type_traits(1712): Reference C2672 : 'std::_Invoker1': too few template arguments
0>type_traits(1680): Reference C2672 : see declaration of 'std::_Invoker1'
0>type_traits(1712): Reference C2672 : '<missingId>': identifier not found
0>type_traits(1703): Reference C2672 : or 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
0>SettingsMenu.cpp(61): Reference C2672 : 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 3 provided
0>SettingsMenu.cpp(63): Error C2439 : 'USettingsMenu::NativeConstruct::<lambda_bbe9ef5ea3be66081a6867a487214d6f>::SetFunc': member could not be initialized
0>SettingsMenu.cpp(63): Reference C2439 : see declaration of 'USettingsMenu::NativeConstruct::<lambda_bbe9ef5ea3be66081a6867a487214d6f>::SetFunc'
And here’s the code itself:
typedef int32(UGameUserSettings::*GetFunc)() const;
typedef void(UGameUserSettings::*SetFunc)(int);
struct FSelectionElement
{
UNF_Base_Selection* Widget;
GetFunc GetFunc;
SetFunc SetFunc;
};
void USettingsMenu::NativeConstruct()
{
Super::NativeConstruct();
GameUserSettings = UGameUserSettings::GetGameUserSettings();
InitializeResolutionComboBox();
InitializeVSync();
InitializeFPS();
const FSelectionElement SelectionElements[] = {
{ Selection_OverallQuality, &UGameUserSettings::GetOverallScalabilityLevel, &UGameUserSettings::SetOverallScalabilityLevel },
{ Selection_ViewDistance, &UGameUserSettings::GetViewDistanceQuality, &UGameUserSettings::SetViewDistanceQuality },
{ Selection_AntiAliasing, &UGameUserSettings::GetAntiAliasingQuality, &UGameUserSettings::SetAntiAliasingQuality },
{ Selection_Shadow, &UGameUserSettings::GetShadowQuality, &UGameUserSettings::SetShadowQuality },
{ Selection_Textures, &UGameUserSettings::GetTextureQuality, &UGameUserSettings::SetTextureQuality },
{ Selection_VisualEffects, &UGameUserSettings::GetVisualEffectQuality, &UGameUserSettings::SetVisualEffectQuality },
{ Selection_Foliage, &UGameUserSettings::GetFoliageQuality, &UGameUserSettings::SetFoliageQuality }
};
for (const auto& [Widget, GetFunc, SetFunc]: SelectionElements)
{
const auto CurrentSelection = std::invoke(GetFunc, GameUserSettings);
Widget->SetCurrentSelection(CurrentSelection);
Widget->OnSelectionChanged.BindLambda([this, SetFunc](int InSelection)
{
std::invoke(SetFunc, GameUserSettings, InSelection);
GameUserSettings->ApplySettings(false);
});
}
}
( Lines with errors: )
for (const auto& [Widget, GetFunc, SetFunc]: SelectionElements)
const auto CurrentSelection = std::invoke(GetFunc, GameUserSettings);
Widget->SetCurrentSelection(CurrentSelection);
std::invoke(SetFunc, GameUserSettings, InSelection);