这是代码,CodeBlocks表示错误在线上shwon:
bool SoccerTeam::isPassSafeFromOpponent(Vector2D from,
Vector2D target,
const PlayerBase* const receiver,
const PlayerBase* const opp,
double PassingForce)const
{
Vector2D ToTarget = target - from;
Vector2D ToTargetNormalized = Vec2DNormalize(ToTarget);
Vector2D LocalPosOpp = PointToLocalSpace(opp->Pos(),
ToTargetNormalized,
ToTargetNormalized.Perp(),
from); // *** ERROR ***
错误讯息:
error: invalid initialization of non-const reference of type 'Vector2D&'
from an rvalue of type 'Vector2D'`
答案 0 :(得分:2)
问题在于第3个参数,您尝试将Vector2D :: Perp()函数的返回值作为参考传递。 (同样适用于第一个参数,但我猜这是一个const Vector2D&,所以它可能不会哭。)尝试以下内容:
bool SoccerTeam::isPassSafeFromOpponent(Vector2D from,
Vector2D target,
const PlayerBase* const receiver,
const PlayerBase* const opp,
double PassingForce)const
{
Vector2D ToTarget = target - from;
Vector2D ToTargetNormalized = Vec2DNormalize(ToTarget);
Vector2D ToTargetNormalizedPerp = ToTargetNormalized.Perp();
Vector2D LocalPosOpp = PointToLocalSpace(opp->Pos(),
ToTargetNormalized,
ToTargetNormalizedPerp,
from);