似乎无法使用结构中的整数
struct stVitals // Entity vitals
{
int str;
int xp;
int batk;
};
int doAttack(stVitals Aggressor, stVitals Defender) // Calculate attack results
{
doHit(getATK(Aggressor), getDEF(Defender), getDDG(Defender), getLVL(Aggressor), getLVL(Defender));
}
int doHit([...] // Calculate damage
int getATK(stVitals sourcemob) // Calculate attack value
{
int output = ((sourcemob.str * getLVL(sourcemob.xp)) * 0.1) + sourcemob.batk;
return output;
}
int getLVL(int xp) // Return level from XP
{
return (xp * 0.001);
}
给出以下错误:
ERROR: Conversion from 'int' to non-scalar type 'stVitals' requested
我以这种方式在程序周围的各种 stVital 实例中使用整数,没有任何问题......我错过了这里发生了什么?
编辑:它在 getATK 内部的第一行大喊大叫
struct stVitals // Entity vitals
{
int str;
int xp;
int batk;
};
int doAttack(stVitals Aggressor, stVitals Defender) // Calculate attack results
{
doHit(getATK(Aggressor), getDEF(Defender), getDDG(Defender), getLVL(Aggressor), getLVL(Defender));
}
int doHit([...] // Calculate damage
int getATK(stVitals sourcemob) // Calculate attack value
{
int output = ((sourcemob.str * getLVL(sourcemob.xp)) * 0.1) + sourcemob.batk;
return output;
}
int getLVL(int xp) // Return level from XP
{
return (xp * 0.001);
}
Gives the following error:
ERROR: Conversion from 'int' to non-scalar type 'stVitals' requested
I work with ints within various stVital instances all around my program in this manner with no problems... what's going on here that I'm missing?
edit: It is hollering about the first line inside of getATK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里缺少的是调用
getATK
的代码。据推测,您在调用该函数时错误地传递了int
参数,而不是stVitals
参数。What's missing here is the code in which you call
getATK
. Presumably, you're incorrectly passing anint
argument rather than anstVitals
argument when you call that function.doAttack() 正在使用 stVitals 调用 getLvl;
getLvl is being called with a stVitals by doAttack();