세트 cpp에있는 요소의 속성을 변경하고는 운영자의 방법 :나는 세트를 정의
set<State*, CompareStateId>::iterator it = consideredState.find(_state);
if(it != consideredState.end()){
if(_state->getStepCount() < *it->getStepCount()){ // [Error] request for member 'getStepCount' in '* it.std::_Rb_tree_const_iterator<_Tp>::operator-><State*>()', which is of pointer type 'State* const' (maybe you meant to use '->' ?)
*it->setStepCount(_state->getStepCount());
}
}
I 돈 :
class CompareStateId {
public:
bool operator()(State *_state1, State *_state2)
{
if (_state2->getId() == _state1->getId()) return true;
return false;
}
};
set<State*, CompareStateId> consideredState;
그런 다음 나는이 세트 상태의 값을 변경하려면 몇 가지 이유 때문에 지우고 다시 삽입하고 싶지 않습니다. 집합 cpp에서 요소의 속성을 변경하는 방법은 무엇입니까?
연산자 우선 순위 ... 또한 쓰지 마십시오. if (cond) return true; return false;', 대신에'return cond;'를 써라. –
@TheParamagneticCroissant'if'에 대한 귀하의 의견은 주제와 관련이 없지만 본질적으로 입문 튜토리얼이나 표준 문서에있는 내용은이 사이트의 주제입니다. – Potatoswatter
@Potatoswatter'if'에 대한 제 의견이 전적으로 적합합니다. –