gpt4 book ai didi

c++ - 交换 bool 值

转载 作者:行者123 更新时间:2023-11-28 01:39:14 25 4
gpt4 key购买 nike

我一直在开发一个菜单,该菜单通过 dll 注入(inject)到使命召唤现代 war 3 中。当我向菜单添加选项时,我想创建一个空白,以便我可以交换 bool 值。

我试过:

void swapBool(bool& xbool)
{
if (xbool)
!xbool;
else if (!xbool)
xbool;
}

但是,它不起作用。这就是我希望它实现的目标:

if (displayInfoBox)
displayInfoBox = false;
else if (!displayInfoBox)
displayInfoBox = true;

因为有那么多 bool 和更多的 bool,我想创建一个 void...

                if (offHostScroll == 0)
{
if (rgbEffects)
rgbEffects = false;
else if (!rgbEffects)
rgbEffects = true;
}
else if (offHostScroll == 1)
{
if (rgbMenu)
rgbMenu = false;
else if (!rgbMenu)
rgbMenu = true;
}
else if (offHostScroll == 2)
{
if (rgbBakcground)
rgbBakcground = false;
else if (!rgbBakcground)
rgbBakcground = true;
}
else if (offHostScroll == 3)
{
if (rgbMaps)
rgbMaps = false;
else if (!rgbMaps)
rgbMaps = true;
}
else if (offHostScroll == 4)
{
if (rgbInGameIcons)
rgbInGameIcons = false;
else if (!rgbInGameIcons)
rgbInGameIcons = true;
}
else if (offHostScroll == 5)
{
swapBool(displayInfoBox);
/*if (displayInfoBox)
displayInfoBox = false;
else if (!displayInfoBox)
displayInfoBox = true;*/
}

最佳答案

简单地:

displayInfoBox = !displayInfoBox;

xbool = !xbool;

! 本身不会改变变量的值,它只是通过取反创建一个新值,所以你必须重新分配它。

您还必须通过引用使 swapBool 传递 xbool

void swapBool(bool& xbool);

关于c++ - 交换 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48030540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com