«ошибка: запрошено преобразование из ‘int’ в нескалярный тип ‘COORD'»

#c

#c

Вопрос:

Я получаю эту одиночную ошибку при попытке скомпилировать следующий код в code::blocks.
Ошибка возникает на 8 строк ниже.

 #include <iostream>
#include <windows.h>
using namespace std;

int main()
{
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos = (40, 3);
SetConsoleCursorPosition(screen, pos);
cout << "O" << endl;
Sleep(500);

for (int tossIt = 1; tossIt <= 3; tossIt  )
{
    while (pos.Y <= 20)
    {
        SetConsoleCursorPosition(screen, pos);
        cout << "|" << endl;
        pos.Y  ;
        SetConsoleCursorPosition(screen, pos);
        cout << "O" << endl;
        Sleep(100);
    }
    while (pos.Y > 3)
    {
        SetConsoleCursorPosition(screen, pos);
        cout << " " << endl;
        pos.Y--;
        SetConsoleCursorPosition(screen, pos);
        cout << "O" << endl;
        Sleep(100);
    }
}
return 0;
}
  

Ответ №1:

 COORD pos = (40, 3);
  

Это должно быть:

 COORD pos = {40, 3};
  

Обратите внимание на использование {} вместо ().

Ответ №2:

 COORD pos = (40, 3); // (40,3) is comma expression, 3 is "retrurned"
COORD pos(40, 3); // you intent?
  

Комментарии:

1. Спасибо за быстрый ответ, но мне нужно было изменить ( на {.