错误:数组下标的类型"const bool[int]"无效
error: invalid types ‘const bool[int]’ for array subscript
有人可以帮助我吗? 我不知道我必须改变什么。我想创建一个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, %dn", 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 };
相关文章:
- 写入向量<向量<bool>>
- 让bool方法返回其他整数
- 如何在 std::vector 中找到<bool>哪些索引是真的?
- Arduino-C++ bool 不会从 false 变为 true
- 为什么在这种情况下,bool 类型的输出等于 0?
- 显式 std::exception_ptr 转换为 bool 不存在.VS2010 错误?
- 错误:不能使用"显式"说明符声明 bool'
- 为什么 C++ 11 在 ios 类中添加了运算符 bool
- 从标准::字符串到标准::矢量<bool>的快速转换
- 为什么 bool 和 _Bool 如果它们在内存中占用 1 个字节,它们只能存储 0 或 1
- 通过 mpi 发送 c++ 标准::矢量<bool>
- 为什么使用Pool和Bool而不是int8_t或char
- 如何为地图< map<int,int> 、bool > 分配值?
- 为什么更改包含 psapi.h 的顺序会产生编译错误?(标识符 BOOL 未定义)
- 使用 bool 和 const char 重载的 C++ 函数会在没有警告的情况下产生歧义 (MSVC2012)
- 返回 bool 作为 CPP 中 bool 运算符 [] 中的值
- 如何告诉自动推断向量<bool>元素的非引用类型
- 当 Type = bool 时,运算符 bool() 与模板 Type() 运算符冲突
- 为什么"std::set::erase(const key_type&)"返回"size_type"而不是"bool"?
- 使用LASlib时BOOL typedef重新定义