开发者

error: expected primary-expression before ‘.’ token

whats the problem of this code that i take the above error?

TIA

#include"PositionInfo.h"

bool DecisionTree::Decision(Agent & agent) {

PositionInfo Player_position;
double metr=Player_position.GetBallDistToTeammate(5);

if (agent.GetSelf().IsKickable()) {

Kicker::instance().KickBall(agent开发者_如何学Python,agent.GetWorldState().GetTeammate(5).GetPos(),metr);

}
}

i changed the code now i got this error:

error: no matching function for call to ‘PositionInfo::PositionInfo()’

Edited:

according to johnsyweb response:

in class PositionInfo we have like this:

    PositionInfo(WorldState *pWorldState, InfoState *pInfoState);

and i put it like this in DecisionTree:

    PositionInfo Player_position(WorldState *pWorldState, InfoState *pInfoState);

   double met=Player_position//but here IDE doesnt let me to put GetBallDistToTeammate() 


A class name is not a primary expression. You should either create an object of type PositionInfo and use that to call GetBallDistToTeammate or use PositionInfo::.


Is it because it should be PositionInfo::GetBallDistToTeammate(5)? I assume this is a static function. . is used in Java/C# and :: in C++ to access static members.

In response to your editing question

It looks like PositionInfo::GetBallDistToTeamMate is not a static member function. You will need an instance of position info (e.g. a variable of that type) to call the method on. It doesn't look like you have one in the function, so maybe there is one as a member of DecisionTree? It's difficult to tell without more information.


PositionInfo is a class. GetBallDistToTeammate() is a method.

Given the name of the function and the number of arguments (one), I would suggest that a static method would not be be able to calculate a distance with that information.

As such you'd need to construct an instance of PositionInfo (let's call it player_position) probably as a member of your DecisionTree and presumably call some other method upon it to set its position (from your edit, its position is set in the constructor PositionInfo::PositionInfo(), which takes at least one argument).

Then in DecisionTree::Decision() you could call player_position.GetBallDistToTeammate(5) and get a number of metres back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜