RelientFX RelientFX - 1 year ago 129
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.

Answer Source

You should use explicit typecast

COORD c = { static_cast<short>(x), static_cast<short>(y) };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download