2014-11-29 1 views
-1

세트 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에서 요소의 속성을 변경하는 방법은 무엇입니까?

+0

연산자 우선 순위 ... 또한 쓰지 마십시오. if (cond) return true; return false;', 대신에'return cond;'를 써라. –

+0

@TheParamagneticCroissant'if'에 대한 귀하의 의견은 주제와 관련이 없지만 본질적으로 입문 튜토리얼이나 표준 문서에있는 내용은이 사이트의 주제입니다. – Potatoswatter

+0

@Potatoswatter'if'에 대한 제 의견이 전적으로 적합합니다. –

답변

1

,

*it->getStepCount() 

가 당신을 위해 무엇을 찾고있는 것은

*(it->getStepCount()) 

과 동일합니다 : 마찬가지로

(*it)->getStepCount() 

, 당신은 사용할 필요가 :

(*it)->setStepCount(_state->getStepCount()); 
1

귀하의 오류는 const 요구 사항과 관련이 없습니다. std::set입니다.

* 연산자는 -> 연산자보다 우선 순위가 낮습니다. *it->setStepCount 대신 (*it)->setStepCount이 필요합니다. 때문에 연산자 우선 순위에

관련 문제