首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“不匹配'operator=‘in",结构错误C++

“不匹配'operator=‘in",结构错误C++
EN

Stack Overflow用户
提问于 2011-10-14 20:59:26
回答 5查看 3.9K关注 0票数 0

当我在g++下编译时,会得到以下错误:

函数

中的'int search(int, int, int)'

1584:错误:'operator=''* tt = & core.<anonymous union>::tt[((hash_stack[ply] >> 16) & 2047ul)]'中不匹配

1584:错误:注:候选人是:

118:注:tt_type& tt_type::operator=(const tt_type&)

118:注:参数1从'tt_type*''const tt_type&'没有已知的转换

代码语言:javascript
复制
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;
    }

我之前定义过的

代码语言:javascript
复制
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 */
};
EN

回答 5

Stack Overflow用户

发布于 2011-10-14 21:03:57

错误消息中最重要的一行是:

代码语言:javascript
复制
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)]更改为浅拷贝将解决问题(取决于您的视角)。

票数 2
EN

Stack Overflow用户

发布于 2011-10-14 21:04:35

我怀疑你的第1584行确实是这样的:

代码语言:javascript
复制
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];

*ttstruct tt_type型的。RHS的形式是&...,所以它是某种指针类型。可以将结构分配给结构,也可以将指针分配给指针,但不能将指针值分配给结构(除非重载了赋值运算符)。

我还没有研究足够的代码来理解它,但是您可能希望将*tt = ...更改为tt = ...

票数 2
EN

Stack Overflow用户

发布于 2011-10-14 21:05:02

代码语言:javascript
复制
*tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];

您正在尝试将指针存储到不是指针的变量中。

你要么需要

代码语言:javascript
复制
*tt = TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];

创建数组的一个元素的副本(这是行不通的,因为tt没有初始化)

代码语言:javascript
复制
tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];

若要使指针指向数组,请执行以下操作。

另一种编写第二个版本的方法是

代码语言:javascript
复制
tt = TTABLE + ((hash_stack[ply]>>16) & (CORE-1));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7773495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档