记录成员变量赋值的坑

先上错误代码:

        //闯红灯1
        if(AgainstRedLight == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstRedLight(labels, algVIRConfigOutput);
        }
        //越线停车2
        if(CoverStopLine == algVIRConfigInput.currentEIllegalType)
        {
            processForCoverStopLine(labels, algVIRConfigOutput);
        }
        //违反导向3
        if(AgainstDirection == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstDirection(labels, algVIRConfigOutput);
        }
        //逆行4
        if(Retrograde == algVIRConfigInput.currentEIllegalType)
        {
            processForRetrograde(labels, algVIRConfigOutput);
        }
        //压实线5
        if(CrossLine == algVIRConfigInput.currentEIllegalType)
        {
            processForCrossLine(labels, algVIRConfigOutput);
        }
        //违法变道6
        if(IllegalLaneChange == algVIRConfigInput.currentEIllegalType)
        {
            processForIllegalLaneChange(labels, algVIRConfigOutput);
        }
        //借道超车7
        if(AgainstInsert == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstInsert(labels, algVIRConfigOutput);
        }
        //手持违停
        if(ViolationParking == algVIRConfigInput.currentEIllegalType)
        {
            processForViolationParking(labels, algVIRConfigOutput);
        }
        //黄网格停车
        if(YellowGridParking == algVIRConfigInput.currentEIllegalType)
        {
            processForYellowGridParking(labels, algVIRConfigOutput);
        }
        //占用公交车道
        if(AgainstBusLaneWithSign == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstBusLaneWithSign(labels, algVIRConfigOutput);
        }
        //占用非机动车道
        if(AgainstBicycleLane == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstBicycleLane(labels, algVIRConfigOutput);
        }
        //占用紧急车道
        if(AgainstEmergencyLane == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstEmergencyLane(labels, algVIRConfigOutput);
        }
        //高速超速
        if(AgainstHighSpeed == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstHighSpeed(labels, algVIRConfigOutput);
        }
        //礼让行人
        if(AgainstLetPedestrian == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstLetPedestrian(labels, algVIRConfigOutput);
        }
        //主驾打电话
        if(AgainstCalling == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstCalling(labels, algVIRConfigOutput);
        }
        //未系安全带
        if(AgainstNoBelt == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstNoBelt(labels, algVIRConfigOutput);
        }
    algVIRConfigOutput_ = algVIRConfigOutput;
int Alg_VIR_config::getConfigStruct(Alg_VIR_configOutput &algVIRConfigOutput)
{
    algVIRConfigOutput.has_confile = algVIRConfigOutput_.has_confile;
    algVIRConfigOutput.algVIRConfigAgainstBicycleLane = algVIRConfigOutput_.algVIRConfigAgainstBicycleLane;
    algVIRConfigOutput.algVIRConfigAgainstBusLaneWithSign = algVIRConfigOutput_.algVIRConfigAgainstBusLaneWithSign;
    algVIRConfigOutput.algVIRConfigAgainstCalling = algVIRConfigOutput_.algVIRConfigAgainstCalling;
    algVIRConfigOutput.algVIRConfigAgainstDirection = algVIRConfigOutput_.algVIRConfigAgainstDirection;
    algVIRConfigOutput.algVIRConfigAgainstEmergencyLane = algVIRConfigOutput_.algVIRConfigAgainstEmergencyLane;
    algVIRConfigOutput.algVIRConfigAgainstHighSpeed = algVIRConfigOutput_.algVIRConfigAgainstHighSpeed;
    algVIRConfigOutput.algVIRConfigAgainstInsert = algVIRConfigOutput_.algVIRConfigAgainstInsert;
    algVIRConfigOutput.algVIRConfigAgainstLetPedestrian = algVIRConfigOutput_.algVIRConfigAgainstLetPedestrian;
    algVIRConfigOutput.algVIRConfigAgainstNoBelt = algVIRConfigOutput_.algVIRConfigAgainstNoBelt;
    algVIRConfigOutput.algVIRConfigAgainstRedLight = algVIRConfigOutput_.algVIRConfigAgainstRedLight;
    algVIRConfigOutput.algVIRConfigCoverStopLine = algVIRConfigOutput_.algVIRConfigCoverStopLine;
    algVIRConfigOutput.algVIRConfigCrossLine = algVIRConfigOutput_.algVIRConfigCrossLine;
    algVIRConfigOutput.algVIRConfigIllegalLaneChange = algVIRConfigOutput_.algVIRConfigIllegalLaneChange;
    algVIRConfigOutput.algVIRConfigRetrograde = algVIRConfigOutput_.algVIRConfigRetrograde;
    algVIRConfigOutput.algVIRConfigViolationParking = algVIRConfigOutput_.algVIRConfigViolationParking;
    algVIRConfigOutput.algVIRConfigYellowGridParking = algVIRConfigOutput_.algVIRConfigYellowGridParking;
}

 

可以看出,我想实现的效果是,每次上层修改了某个违法类型的规则之后,对algVIRConfigOutput中相应的成员变量进行修改,然后赋值给algVIRConfigOutput_(类的私有成员变量,全局的),通过调用getConfigStruct函数,将algVIRConfigOutput_中保存的内容传递出去;

但是实际却没有达到上述效果,algVIRConfigOutput中存储的貌似还是默认值;

后来经过调试发现问题所在:

在algVIRConfigOutput_ = algVIRConfigOutput;这个语句中,将algVIRConfigOutput中的值赋值给algVIRConfigOutput_,例如,闯红灯调用了该函数进行规则配置,上层传递的只是闯红灯的规则配置修改了,违反导向由于没有传递进行,algVIRConfigOutput中相应的变量值还保持着初始化的时候的变量值(也就是默认值),然后在赋值给algVIRConfigOutput_的时候,违反导向的相应值又会被覆盖掉,同理,修改违反导向的时候,也会把闯红灯的覆盖为默认值。

 

后续修改的代码如下:

//闯红灯1
        if(AgainstRedLight == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstRedLight(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstRedLight = algVIRConfigOutput.algVIRConfigAgainstRedLight;
        }
        //越线停车2
        if(CoverStopLine == algVIRConfigInput.currentEIllegalType)
        {
            processForCoverStopLine(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigCoverStopLine = algVIRConfigOutput.algVIRConfigCoverStopLine;
        }
        //违反导向3
        if(AgainstDirection == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstDirection(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstDirection = algVIRConfigOutput.algVIRConfigAgainstDirection;
        }
        //逆行4
        if(Retrograde == algVIRConfigInput.currentEIllegalType)
        {
            processForRetrograde(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigRetrograde = algVIRConfigOutput.algVIRConfigRetrograde;
        }
        //压实线5
        if(CrossLine == algVIRConfigInput.currentEIllegalType)
        {
            processForCrossLine(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigCrossLine = algVIRConfigOutput.algVIRConfigCrossLine;
        }
        //违法变道6
        if(IllegalLaneChange == algVIRConfigInput.currentEIllegalType)
        {
            processForIllegalLaneChange(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigIllegalLaneChange = algVIRConfigOutput.algVIRConfigIllegalLaneChange;
        }
        //借道超车7
        if(AgainstInsert == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstInsert(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstInsert = algVIRConfigOutput.algVIRConfigAgainstInsert;
        }
        //手持违停
        if(ViolationParking == algVIRConfigInput.currentEIllegalType)
        {
            processForViolationParking(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigViolationParking = algVIRConfigOutput.algVIRConfigViolationParking;
        }
        //黄网格停车
        if(YellowGridParking == algVIRConfigInput.currentEIllegalType)
        {
            processForYellowGridParking(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigYellowGridParking = algVIRConfigOutput.algVIRConfigYellowGridParking;
        }
        //占用公交车道
        if(AgainstBusLaneWithSign == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstBusLaneWithSign(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstBusLaneWithSign = algVIRConfigOutput.algVIRConfigAgainstBusLaneWithSign;
        }
        //占用非机动车道
        if(AgainstBicycleLane == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstBicycleLane(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstBicycleLane = algVIRConfigOutput.algVIRConfigAgainstBicycleLane;
        }
        //占用紧急车道
        if(AgainstEmergencyLane == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstEmergencyLane(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstEmergencyLane = algVIRConfigOutput.algVIRConfigAgainstEmergencyLane;
        }
        //高速超速
        if(AgainstHighSpeed == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstHighSpeed(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstHighSpeed = algVIRConfigOutput.algVIRConfigAgainstHighSpeed;
        }
        //礼让行人
        if(AgainstLetPedestrian == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstLetPedestrian(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstLetPedestrian = algVIRConfigOutput.algVIRConfigAgainstLetPedestrian;
        }
        //主驾打电话
        if(AgainstCalling == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstAgainstCalling(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstCalling = algVIRConfigOutput.algVIRConfigAgainstCalling;
        }
        //未系安全带
        if(AgainstNoBelt == algVIRConfigInput.currentEIllegalType)
        {
            processForAgainstNoBelt(labels, algVIRConfigOutput);
            algVIRConfigOutput_.algVIRConfigAgainstNoBelt = algVIRConfigOutput.algVIRConfigAgainstNoBelt;
        }

 

正确运行。

 

posted @ 2019-02-14 14:02  rainsoul  Views(497)  Comments(0Edit  收藏  举报