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) };更多推荐
发布评论