user975900
user975900

Reputation: 77

"No match for 'operator=' in", structs error C++

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

Upvotes: 0

Views: 4433

Answers (5)

Mooing Duck
Mooing Duck

Reputation: 66922

*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.

Upvotes: 0

Ben Voigt
Ben Voigt

Reputation: 283684

*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));

Upvotes: 1

Keith Thompson
Keith Thompson

Reputation: 263277

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 = ....

Upvotes: 2

user405725
user405725

Reputation:

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).

Upvotes: 2

Seth Carnegie
Seth Carnegie

Reputation: 75130

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).

Upvotes: 0

Related Questions