【问题标题】:convert 'this' pointer from item to const Item & compiler errors将“this”指针从 item 转换为 const Item & 编译器错误
【发布时间】:2015-01-16 16:47:20
【问题描述】:

您能否解释一下为什么会发生以下错误以及如何解决该问题?它给我带来了很多问题,所以我需要你的帮助

错误(编译错误)-

the object has type qualifiers that are not compatible with the member function

*items 成员是一个集合

问题线——

temp.setName(items.find(itemList[option])->getName());

setName 和 getName 函数 -

void Item::setName(string name)
{
    this->_name = name;
}
string Item::getName()
{
    return this->_name;
}

【问题讨论】:

    标签: c++ function compiler-errors set


    【解决方案1】:

    您的方法不正确。该集合只允许对其内容使用常量方法:

    string Item::getName() const
    {
        return this->_name;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2013-11-18
      • 2021-02-11
      • 2015-04-04
      • 2011-09-30
      • 2021-06-11
      • 1970-01-01
      相关资源
      最近更新 更多