错误:没有匹配的函数可以调用sth [英] error: no matching function for call to sth
本文介绍了错误:没有匹配的函数可以调用sth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在另一个类中使用一个类的方法,但是在下面出现错误,这是什么问题?
TIA
错误:没有匹配的函数可以调用"PositionInfo :: PositionInfo()"
这是我的代码:
PositionInfo Pos;
double metr = Pos.GetBallDistToTeammate( 5 );///我在这里遇到了错误
和PositionInfo.h类为:
PositionInfo(WorldState * pWorldState,InfoState * pInfoState);
和PositionInfo.cpp类为:
const double & GetBallDistToTeammate(Unum unum)常量 {Assert(unum > 0 ); 返回 GetBallDistToPlayer(unum); }
解决方案
您必须执行以下任一操作:
- 定义不带
PositionInfo
类参数的构造函数(即PositionInfo::PositionInfo()
).
或
- 在
Pos
变量定义(例如PositionInfo Pos(NULL, NULL);
)中使用您已经定义的构造函数.
PositionInfo类应类似于这个:
class PositionInfo { public: PositionInfo() {}; // replace with your constructor double GetBallDistToPlayer(Unum unum) const { return X; // return your value here } double GetBallDistToTeammate(Unum unum) const { return GetBallDistToPlayer(unum); } };
我认为您可能需要定义一个采用int的GetBallDistToTeammate函数,或将参数转换为Unum ...
>
hi,
i want to use a method of a class in another class,but i get error below,whats the problem?
TIA
error: no matching function for call to ‘PositionInfo::PositionInfo()’
here is my code:
PositionInfo Pos;
double metr=Pos.GetBallDistToTeammate(5);///i got the error here
and PositionInfo.h class is:
PositionInfo(WorldState *pWorldState, InfoState *pInfoState);
and PositionInfo.cpp class is:
const double & GetBallDistToTeammate(Unum unum) const { Assert(unum > 0); return GetBallDistToPlayer(unum); }
解决方案
You must either:
- define the contructor without arguments for the
PositionInfo
class (i.e.PositionInfo::PositionInfo()
).
or
- Use your already defined contructor in the
Pos
variable definition (e.g.PositionInfo Pos(NULL, NULL);
).
The class PositionInfo should be like this:
class PositionInfo { public: PositionInfo() {}; // replace with your constructor double GetBallDistToPlayer(Unum unum) const { return X; // return your value here } double GetBallDistToTeammate(Unum unum) const { return GetBallDistToPlayer(unum); } };
I think that perhaps you need to define a GetBallDistToTeammate function that takes an int, or cast the parameter to a Unum...
这篇关于错误:没有匹配的函数可以调用sth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文