Alon
Alon

Reputation: 27

convert 'this' pointer from item to const Item & compiler errors

Can you explain me why the following error happens and How I can fix the problem? It gives me a lot of problems so please I need your help

the error(compilation error) -

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

*the items member is a set

the problem line -

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

the setName and the getName functions -

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

Upvotes: 1

Views: 81

Answers (1)

nvoigt
nvoigt

Reputation: 77304

Your method is not const-correct. The set will only allow constant methods on it's contents:

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

Upvotes: 3

Related Questions