RelientFX RelientFX - 7 months ago 50
C++ Question

C++ COORD error

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

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


You should use explicit typecast

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