"与 'operator=' 不匹配in”,结构错误 C++
当我在 g++ 下编译时,出现以下错误:
在函数
'int search(int, int, int)'
中:1584:错误:
'* tt = & 中的
'operator='
不匹配core.<匿名联合>::tt[((hash_stack[ply] >> 16) & 2047ul)]'1584:错误:注意:候选人是:
118:注意:
tt_type& tt_type::operator=(const tt_type&)
118:注意:参数 1 从
'tt_type*'
到'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 */
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
错误消息中最重要的一行是:
它本质上意味着您正在尝试将指针分配给引用。
这反过来又让我认为改变
* tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
将代码中的* tt = core.::tt[((hash_stack[ply] > ;> 16) & 2047ul)]
用于深层复制或tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
浅复制将解决问题(取决于您的观点)。The most important line in the error message is this:
It essentially means that you are trying to assign a pointer to the reference.
Which in turn makes me think that changing
* tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
in your code to* tt = core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
for deep copy or tott = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)]
for shallow copy will solve the problem (depending on your perspective).我怀疑你的第 1584 行确实是这样的:
*tt
是struct tt_type
类型。 RHS 的形式为&...
,因此它属于某种指针类型。您可以将结构分配给结构,或将指针分配给指针,但不能将指针值分配给结构(除非您重载了赋值运算符)。我对代码的研究还不够充分,无法理解它,但您可能想将
*tt = ...
更改为tt = ...
。I suspect that your line 1584 is really this one:
*tt
is of typestruct tt_type
. The RHS is of the form&...
, so it's of some pointer type. You can assign a struct to a struct, or a pointer to a pointer, but you can't assign a pointer value to a struct (unless you've overloaded the assignment operator).I haven't studied the code enough to understand it, but you probably want to change
*tt = ...
tott = ...
.您试图将指针存储到不是指针的变量中。
您需要
复制数组的一个元素(这不起作用,因为 tt 未初始化)
或
创建指向数组的指针。
编写第二个版本的另一种方法是
You're trying to store a pointer into a variable that's not a pointer.
You need either
to make a copy of one element of the array (this isn't going to work, since
tt
is not initialized)or
to make a pointer into the array.
Another way of writing the second version is
在这一行中:
您尝试将
tt_type
类型的变量分配给其他类型的另一个事物。我不知道TTABLE
是什么,但作为一个疯狂的猜测,尝试删除&
(如果&
会导致错误TTABLE
是一个tt_type
数组,您会尝试将tt_type*
分配给tt_type
) 。In this line:
You're trying to assign a variable of type
tt_type
to another thing of some other type. I don't know whatTTABLE
is, but as a wild guess, try removing the&
(the&
would cause an error ifTTABLE
is an array oftt_type
s. You'd be trying to assign att_type*
to att_type
).*tt = &TTABLE[/**/];
您正在从指针分配结构。正如
noknown conversion for argument 1 from'tt_type*' to 'const tt_type&'
所澄清的,它无法将tt_type*
转换为tt_type&
> 制作副本。我不知道
TTABLE
是什么,但我会从中删除&
。*tt = &TTABLE[/**/];
You're assigning your struct from a pointer. As clarified by
no known conversion for argument 1 from'tt_type*' to 'const tt_type&'
It cannot convert thett_type*
to att_type&
to make the copy.I don't know what
TTABLE
is, but I'd remove the&
from it.