c++ - 错误:数组下标的类型“const bool [int]”无效
问题描述
请问有人可以帮助我吗?我不知道我必须改变什么。我想创建一个 2D 网格和其他一些东西。
这是我的代码中最重要的部分。
#include <ncurses.h>
bool cells;
const MAX_GRID_SIZE;
//_________________________________________________
void initializeGame() {
initscr();
cbreak();
noecho();
curs_set(false);
nodelay(stdscr, true);
keypad(stdscr, true);
mousemask(ALL_MOUSE_EVENTS, NULL);
// Cells (0 = false, 1 = true).
MAX_GRID_SIZE = 500
cells[MAX_GRID_SIZE][MAX_GRID_SIZE] = { 0 };
}
//_________________________________________________
void showState() {
while (true) {
MEVENT event;
int key = getch();
if (key == KEY_MOUSE) {
if (getmouse(&event) == OK && (event.bstate & BUTTON1_CLICKED)) {
int x = event.x;
int y = event.y;
mvprintw(0, 0, "Mouse clicked at %d, %d\n", x, y);
cells[x][y] = !cells[x][y];
if (cells[x][y] == true) { attron(A_REVERSE); }
mvprintw(y, x, " ");
attroff(A_REVERSE);
refresh();
}
}
}
// Clean up.
endwin();
}
解决方案
如果cells
是一个 2D 数组,则将其声明为:
const size_t MAX_GRID_SIZE = 500;
bool cells[MAX_GRID_SIZE][MAX_GRID_SIZE] = { 0 };
推荐阅读
- flask - Airflow Webserver 访问日志的位置
- mongodb - 如何从 MongoDB 中的查询创建集合?
- python - 在 Python re.sub 函数中,如何使用 \n 语法引用组 0?
- android - Android:ListView 适配器能否将其构造函数的上下文用于 Toast?
- javascript - 返回响应头 OnAuthenticationFailed
- sql - Hive 中的窗口函数
- reactjs - 有没有办法使用流来限制特定的字符串模式?
- grafana - Ceph Luminous 的 Collectd 插件问题
- javascript - 如何执行这两个 OnScrolls?
- google-analytics - GA BigQuery 导出 - COUNT(DISTINCT(fullVisitorId)) 与源/媒介多算