C 错误C3892:您无法分配const变量



我有一个错误:您无法分配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;
        }
    }

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

您无法修改set中存储的元素。他们一定是const。取而代之的是,将其删除并通过修改再次插入。

您搜索了吗?

如何修改从std :: set :: find((

从迭代器指向的对象

c stl集更新很乏味:我无法更改元素

当您修改std :: set的元素时会发生什么?

最新更新