这句话是什么意思? [英] What does this statement mean?

查看:108
本文介绍了这句话是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ship *player = static_cast<Ship *>(a == player_ ? a : (b == player_ ? b : 0));








我知道static_cast是什么,但我不知道使用条件运算符完成了什么。






I know what static_cast is but I don't know what's done with the conditional operators.

First-chance exception at 0x00DDD250 in AsteroidsTest_2012.exe: 0xC0000005: Access violation reading location 0xFEEEFEF6.





我只需要提示可能出现的问题。不直接的答案。我会自己找到答案。我只需要提示。



顺便说一下崩溃就把我带到这里: -





I just need hints about what might be wrong. Not direct answers. I'll find the answer on my own. I just need the hint.

Btw the crash takes me here: -

void Collision::DoCollisions(Game *game) const
{
	for (ColliderList::const_iterator colliderAIt = colliders_.begin(), end = colliders_.end();
		colliderAIt != end;
		++colliderAIt)
	{
		ColliderList::const_iterator colliderBIt = colliderAIt;
		for (++colliderBIt; colliderBIt != end; ++colliderBIt)
		{
			Collider *colliderA = *colliderAIt;
			Collider *colliderB = *colliderBIt;
			if (CollisionTest(colliderA, colliderB))
			{
				game->DoCollision(colliderA->entity, colliderB->entity);
			}
		}
	}
}





我尝试了什么:



尝试纠正这个问题,但我落在这个代码上



What I have tried:

Tried rectifying the problem but I land on this code

推荐答案

看看它:它只是一个嵌套的条件。

Look at it: it's just a nested conditional.
a == player_ ? a : (b == player_ ? b : 0)



如果a == player_则返回a。

否则如果b == player_然后它返回b。

如果两个测试都失败则返回0



将其视为就地:


If a == player_ then it returns a.
Otherwise if b == player_ then it returns b.
If both tests fail it returns 0

Think of it as an "in place if":

if (a == player_)
   return a;
else if (b == player_)
   return b;
return 0;


这篇关于这句话是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆