【发布时间】:2016-04-24 11:19:47
【问题描述】:
ref void init_board (ref int side, ref char[][] board) //make empty symbol chessboard
{
const char black = ' ';
const char white = 0xB0;
board[0][0] = ' ';
for (int i = 1; i <= side; i++)
{
board[i][0] = 0x30 + i; //Setting nums; "Error: Cannot convert int to char"
board[0][i] = 0x40 + i; //Setting letters; same here
for (int j = 1; j <= side; j++)
board[i][j] = (i+j)%2 == 0 ? black : white; //making black-white board
}
}
我正在尝试制作一个简单的符号棋盘。如何根据行/列数正确设置数字和字母? board[i][0] = 0x30 + i;(或 0x40)在 C++ 中有效,但在 D 中无效。
【问题讨论】:
-
ref void是做什么的? -
@Kerbiter 为什么你在那里使用 ref ?在其中任何一个?
ref int仅被读取时完全是浪费,ref char[][]同样只是在这里添加了另一个间接性,没有任何好处。