• "与 'operator=' 不匹配in”,结构错误 C++

    发布于 2024-12-09 23:02:49 字数 2101 浏览 1 评论 0 原文

    当我在 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 */
    };
    

    When I compile under g++ I get the following errors:

    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;
        }
    

    Where I have previously defined

    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 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(5

    小ぇ时光︴ 2024-12-16 23:02:50

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

    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)] 浅复制将解决问题(取决于您的观点)。

    The most important line in the error message is this:

    118:note: no known conversion for argument 1 from 'tt_type*' to 'const tt_type&'
    

    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 to tt = & core.::tt[((hash_stack[ply] >> 16) & 2047ul)] for shallow copy will solve the problem (depending on your perspective).

    妥活 2024-12-16 23:02:50

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

    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

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

    我对代码的研究还不够充分,无法理解它,但您可能想将 *tt = ... 更改为 tt = ...

    I suspect that your line 1584 is really this one:

    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    *tt is of type struct 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 = ... to tt = ....

    蓝海 2024-12-16 23:02:50
    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    您试图将指针存储到不是指针的变量中。

    您需要

    *tt = TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    复制数组的一个元素(这不起作用,因为 tt 未初始化)

    tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    创建指向数组的指针。

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

    tt = TTABLE + ((hash_stack[ply]>>16) & (CORE-1));
    
    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    You're trying to store a pointer into a variable that's not a pointer.

    You need either

    *tt = TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    to make a copy of one element of the array (this isn't going to work, since tt is not initialized)

    or

    tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    to make a pointer into the array.

    Another way of writing the second version is

    tt = TTABLE + ((hash_stack[ply]>>16) & (CORE-1));
    
    烟柳画桥 2024-12-16 23:02:50

    在这一行中:

    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    您尝试将 tt_type 类型的变量分配给其他类型的另一个事物。我不知道 TTABLE 是什么,但作为一个疯狂的猜测,尝试删除 & (如果 & 会导致错误TTABLE 是一个 tt_type 数组,您会尝试将 tt_type* 分配给 tt_type) 。

    In this line:

    *tt = &TTABLE[ ((hash_stack[ply]>>16) & (CORE-1)) ];
    

    You're trying to assign a variable of type tt_type to another thing of some other type. I don't know what TTABLE is, but as a wild guess, try removing the & (the & would cause an error if TTABLE is an array of tt_types. You'd be trying to assign a tt_type* to a tt_type).

    时光瘦了 2024-12-16 23:02:50

    *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 the tt_type* to a tt_type& to make the copy.

    I don't know what TTABLE is, but I'd remove the & from it.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文