警告 C4244:“争论”; :从“int”转换;为“浮动”,可能会丢失数据 (C++)
struct Vector {
float i,j,k;
} std::vector pt[size];
... = ... + pt[temp];
temp
的类型为 int
。编译器给出警告作为标题。
struct Vector {
float i,j,k;
} std::vector pt[size];
... = ... + pt[temp];
temp
is of type int
. Compiler gives the warning as the title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到此警告是因为编译器将
int
隐式转换为float
。可能的原因可能是这样的
You get this warning because the compiler is implicitly converting an
int
to afloat
.A possible cause can be something like
很难说,因为您隐藏了大部分代码,并且我们看不到存储在 std::vector 中的数据类型,因为您要么发布了错误的代码,要么删除了模板参数。
正在添加什么?
pt
是否存储浮点数?像这样的行:可能会生成此警告,因为
x
会隐式转换为 int。It's hard to say given that you've hidden much of the code, and we can't see the type of data that is stored in the std::vector, as you've either posted bad code or removed the template argument.
What is being added? Does
pt
store floats? A line like:May generate this warning since there will be an implicit conversion of
x
to an int.