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;