BOOST_FOREACH는 GroupMember 클래스의 멤버로 존재하는 weak_ptr을 무효화합니다. 이유를 이해하도록 도와주세요.BOOST_FOREACH-loop 내부에 설정된 변수가 루프 외부에서 유효하지 않습니다. 이유가 무엇입니까?
class GroupMember
{
bool logInState;
boost::weak_ptr<CUser> wpUser;
};
GroupMember::iterator it;
BOOST_FOREACH(EachLevel aLevel, levels)
{
if(aLevel.exist(spUser))
{
it = aLevel.getIteratorToGroupMember(spUser);
//iterator (it) is valid as well as the group member's attributes (and weak_ptr)
}
}
//Iterator (it) seems to be valid but the weak_ptr is invalid.
//The counter to the object is more than 10 so the weak ptr is not expired.
아래의 코드가 완벽하게 작동합니다 :
GroupMember::iterator it;
std::vector<EachLevel>::iterator itLevel;
for(itLevel = levels.begin(); itLevel != levels.end(); ++itLevel)
{
if(itLevel->exist(spUser))
it = itLevel->getIteratorToGroupMember(spUser);
}
//Here is iterator (it) valid (including the weak_ptr)
나는 그 차이를 볼 수 없습니다, 당신이 할 수
아래의 코드는 오류를 설명?
감사합니다.
아아, 알겠습니다! 추가 된 참조와 함께 작동합니다. – user521048