游戏程序报错:表达式必须是可修改的左值

C++编程:表达式必须是可修改的左值

报错:
①表达式必须是可修改的左值 "weaponType":不能给常量赋值
②表达式必须是可修改的左值 “=”:左操作数必须为左值

如图一:

img

如图二:

img

图一:

#include "aimbot.h"

#include "../core/globals.h"
#include "../core/interfaces.h"

void hacks::RunAimbot(CUserCmd* cmd) noexcept
{
    // check if we are trying to shoot
    if (!(cmd->buttons & CUserCmd::IN_ATTACK))
        return;

    if (globals::localPlayer->IsDefusing())
        return;

    CEntity* activeWeapon = globals::localPlayer->GetActiveWeapon();

    if (!activeWeapon)
        return;

    const int weaponType = activeWeapon->GetWeaponType();

    switch (weaponType)
    {
    case CEntity::WEAPONTYPE_MACHINEGUN:
    case CEntity::WEAPONTYPE_RIFLE:
    case CEntity::WEAPONTYPE_SHOTGUN:
    case CEntity::WEAPONTYPE_SNIPER:
    case CEntity::WEAPONTYPE_PISTOL:
    {
        if (!activeWeapon->GetClip())
            return;

        if (weaponType = CEntity::WEAPONTYPE_SNIPER)
        {
            if (!globals::localPlayer->IsScoped())
                return;
        }

        break;
    }

    default:
        return;
    }

图二:

CVector bestAngle{ };
    float bestFov{ 5.f };

    for (int i = 1; i <= interfaces::globals->maxClients; ++i)
    {
        CEntity* player = interfaces::entityList->GetEntityFromIndex(i);

        if (!player)
            continue;

        if (player->IsDormant() || !player->IsAlive())
            continue;

        if (player->GetTeam() = globals::localPlayer->GetTeam())
            continue;

        if (player->HasGunGameImmunity())
            continue;

        // player's bone matrix
        CMatrix3x4 bones[128];
        if (!player->SetupBones(bones, 125, 256, interfaces::globals->currentTime))
            continue;

        // our eye position
        CVector localEyePostition;
        globals::localPlayer->GetEyePosition(localEyePostition);

        // our aim punch
        CVector aimPunch{ };

        switch (weaponType)
        {
        case CEntity::WEAPONTYPE_RIFLE:
        case CEntity::WEAPONTYPE_SUBMACHINEGUN:
        case CEntity::WEAPONTYPE_MACHINEGUN:
            globals::localPlayer->GetAimPunch(aimPunch);
        }

判断相等是用两个等于号==不是一个,一个表示赋值

谢谢你的回答,还有一点就是我这个程序最后出来时dll的,我把结尾改成exe后显示此应用无法在你的电脑上运行,这应该怎么解决?

为什么能敲出这么复杂的代码,会不知道判等是==,赋值是=咧,我记得大一上学期第一个月就被==坑了2次,想了一个小时才发现把==写成了=