【问题标题】:c++ error c3892 : You can not assign a const variablec++ 错误 c3892:您不能分配 const 变量
【发布时间】:2017-04-18 06:58:08
【问题描述】:

我有一个错误: 您不能分配 const 变量

类:

    class RegChannel {
public:
    std::string channelID;
    std::string pwd;
    DWORD color;
    bool  bActive;

    bool operator < (const RegChannel &r) const {
        return(stricmp(channelID.c_str(), r.channelID.c_str()) < 0);
    }
};

std::set< RegChannel > regChannels;
std::map< std::string, DWORD > savedColor;
std::map< std::string, bool  > savedStatus;

功能:

        set< RegChannel >::iterator j;
    for( j = chatterUI->regChannels.begin(); j != chatterUI->regChannels.end(); j++ )
    {
       if( stricmp( (*j).channelID.c_str(), channelUI->channelID.c_str() ) == 0 )
        {
            (*j).color = channelUI->channelColor;
        }
    }

你能帮帮我吗? (对不起我的英语不好......)

【问题讨论】:

    标签: c++ visual-studio-2015


    【解决方案1】:

    您不能修改存储在set 中的元素。它们必然是常量。相反,删除它并在修改后再次插入它。

    你搜索了吗?

    How to modify object pointed to by iterator from std::set::find()

    C++ STL set update is tedious: I can't change an element in place

    what happens when you modify an element of an std::set?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      相关资源
      最近更新 更多