当我在 g++ 下编译时,出现以下错误:
In function
'int search(int, int, int)'
:1584:error: no match for
'operator='
in'* tt = & core.<anonymous union>::tt[((hash_stack[ply] >> 16) & 2047ul)]'
1584:error: note: candidate is:
118:note:
tt_type& tt_type::operator=(const tt_type&)
118:note: no known conversion for argument 1 from
'tt_type*'
to'const tt_type&'
static int search(int depth, int alpha, int beta) {
int best_score = -INF;
int best_move = 0;
int score;
struct move *moves;
int incheck = 0;
struct tt_type *tt; //LINE 1584
int oldalpha = alpha;
int oldbeta = beta;
int i, count=0;
nodes++;
/* test for draw by repetition */
hash_stack[ply] = compute_hash();
for (i=ply-4; i>=board[LAST]; i-=2) {
if (hash_stack[i] == hash_stack[ply]) count++;
if (count>=2) return 0;
}
/*
* check transposition table
*/
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
if (tt->hash == (hash_stack[ply] & 0xffffU)) {
if (tt->depth >= depth) {
if (tt->flag >= 0) alpha = MAX(alpha, tt->score);
if (tt->flag <= 0) beta = MIN(beta, tt->score);
if (alpha >= beta) return tt->score;
}
best_move = tt->move & 07777;
}
我之前定义过的地方
struct tt_type { //LINE 118
unsigned short hash; /* - Identifies position */
short move; /* - Best recorded move */
short score; /* - Score */
char flag; /* - How to interpret score */
char depth; /* - Remaining search depth */
};
最佳答案
错误消息中最重要的一行是:
118:note: no known conversion for argument 1 from 'tt_type*' to 'const tt_type&'
这实际上意味着您正在尝试将指针分配给引用。
这反过来又让我想到将代码中的 * tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
更改为 * tt = core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
用于深度复制或到 tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
对于浅拷贝将解决问题(取决于您的观点)。
关于c++ - "No match for ' operator= ' in", 结构错误 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7773495/