c++ - "No match for ' operator= ' in", 结构错误 C++

标签 c++ struct operators

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

相关文章:

javascript - js函数中的'语法错误,意外标记='

java - 实现常量对象的最佳方法是什么?

c++ - 正则表达式括号表达式中的反斜杠

c++ - 用于读取 DVD FS(数据光盘)的 lib

struct - 为什么在 Rust 中允许返回当前函数拥有的引用?

javascript - 这个我到现在都没见过的 JavaScript 语法,它到底做了什么?

c++ - Qt中如何使用MS access?

ios - 无法在 Swift 中访问可编码的结构值

C 编译错误 : array type has incomplete element type

javascript - 在 .includes() 中使用逻辑运算符——出现错误