RelientFX RelientFX - 2 months ago 5
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
conversion.


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

Answer

You should use explicit typecast

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