C ++ COORD错误(C++ COORD error)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
C ++ COORD错误(C++ COORD error)

我正在尝试创建一个俄罗斯方块游戏,当我称之为:

void PrintChar(int x, int y, char ch, Colors color) { COORD c = { y,x }; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, NULL); FillConsoleOutputAttribute(GameData::handle, color, 1, c, NULL); }

出现此警告:

C4838 - 从'int'转换为'SHORT'需要缩小转换。

有人可以解释这里发生了什么,一个小例子将不胜感激。

I'm currently trying to create a Tetris game and when I call this:

void PrintChar(int x, int y, char ch, Colors color) { COORD c = { y,x }; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, NULL); FillConsoleOutputAttribute(GameData::handle, color, 1, c, NULL); }

this Warning comes up:

C4838 - conversion from 'int' to 'SHORT' requires a narrowing conversion.

Could someone please explain what is happening here and a small example would be greatly appreciated.

最满意答案

您应该使用显式类型转换

COORD c = { static_cast<short>(x), static_cast<short>(y) };

You should use explicit typecast

COORD c = { static_cast<short>(x), static_cast<short>(y) };

更多推荐

本文发布于:2023-04-24 20:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/337265fa74668e89521e390007c7aa60.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   COORD   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!