1

Marcel の Simple Chess Program http://marcelk.net/mscp/ を C から C++ に移植する作業を行っています。私はユニオンをあまり扱ったことがなく、ユニオン内の構造体についてはあまり扱ったことがありません。私がリストした一番上の部分は、組合の宣言です。(すべてのコードは 1 つの .c ファイルにあります)。

C++ の教科書に加えて、いくつかのガイドを検索して読みましたが、これを修正する方法についてはまだ洞察が得られていません。「前方c宣言」とは何か、またどのような文脈で問題を見なければならないのかわかりません。

私のコンパイルオプションは

g++ -ansi -Wall -O2 -pedantic -o mscp -mscp.cpp

static union {
        struct tt {                     /* Transposition table entry */
                unsigned short hash;    /* - Identifies position */ 
                short move;             /* - Best recorded move */
                short score;            /* - Score */
                char flag;              /* - How to interpret score */
                char depth;             /* - Remaining search depth */
        } tt[CORE];
        struct bk {                     /* Opening book entry */
                unsigned long hash;     /* - Identifies position */
                short move;             /* - Move for this position */
                unsigned short count;   /* - Frequency */
        } bk[CORE];
} core;

これらの部分は、エラーが発生する行の例です。

エラー: 'const struct cmp_bk(const void*, const void*)::bk' の前方宣言

エラー: 不完全な型 'const struct cmp_bk(const void*, const void*)::bk' の無効な使用</p>

    static int cmp_bk(const void *ap, const void *bp)
    {
            const struct bk *a = ap; //ERROR HERE
            const struct bk *b = bp; //ERROR HERE

            if (a->hash < b->hash) return -1; //ERROR HERE
            if (a->hash > b->hash) return 1; //ERROR HERE
            return (int)a->move - (int)b->move; //ERROR HERE
    }

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                       *tt; //ERROR HERE
        int                             oldalpha = alpha;
        int                             oldbeta = beta;
        int                             i, count=0;

               if (tt->depth >= depth) {
                    if (tt->flag >= 0) alpha = MAX(alpha, tt->score); //ERROR HERE
                    if (tt->flag <= 0) beta = MIN(beta,  tt->score); //ERROR HERE
                    if (alpha >= beta) return tt->score;
            }
            best_move = tt->move & 07777;      
4

1 に答える 1

0

コードのどこかでaclassまたはを宣言したようです。struct bkまた

struct tt                       *tt;

struct と同じ名前の変数を宣言しようとしているため、エラーが発生します (両方とも と呼ばれttます)。このエラーのため、変数が適切に宣言されていないため、他のエラーが発生します。bk実際、問題の多くは、変数と同じ名前のデータ型 (例: )に起因しているように見えttます。可能であれば、データ型の名前を変更するか、匿名にしてみてください。

補足として、ユニオン内の構造体は、他の場所で使用されない限り、おそらく匿名にすることができます。

于 2013-01-28T06:16:25.997 に答える