所以这是一个例子.恒星的mLocation和mSpeed是一个Vector3自定义类型.
我试过了:
Star &star = *iStar;
Star star = *iStar;
Run Code Online (Sandbox Code Playgroud)
iStar->直接使用不适合我的操作员,不知道为什么.那么这样做的正确方法是什么?
void UniverseManager::ApplySpeedVector()
{
std::list <Star>::const_iterator iStar;
for (iStar = mStars.begin(); iStar != mStars.end(); ++iStar)
{
// how to I get a hold on the object the iterator is pointing to so I can modify its values
// i tried Star &star = *iStar; this is illegal
// tried just using the iStar->mLocation += iStar->mSpeed this also fails due to the operator not accepting the values not sure why
// tried other things as well, so what is the proper way to do this?
iStar->SetLocationData( iStar->mLocation += iStar->mSpeed);
}
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)std::list<Star>::const_iterator iStar;
您无法通过a修改容器中的对象const_iterator.如果要修改对象,则需要使用iterator(即std::list<Star>::iterator).
| 归档时间: |
|
| 查看次数: |
14466 次 |
| 最近记录: |