【发布时间】:2011-10-14 00:35:46
【问题描述】:
我在 g++ 下编译时不断收到以下错误(这些是更长的代码段)
错误:无效使用不完整类型'const struct cmp_bk(const void*, const void*)::bk'
错误:'const struct cmp_bk(const void*, const void*)::bk'的前向声明
代码如下:
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;
稍后在程序中,我们定义了新的结构 a, b
static int cmp_bk(const void *ap, const void *bp)
{
const struct bk *a = (bk*) ap;
const struct bk *b = (bk*) bp;
if (a->hash < b->hash) return -1;
if (a->hash > b->hash) return 1;
return (int)a->move - (int)b->move;
}
我们可能(?)无法访问联合之外的结构 bk
【问题讨论】:
-
对不起,这不是 C++。我们在这里不使用
void*。或 C 风格的演员表。或者工会。或者比较不是运算符的函数。 -
@CatPlusPlus - 如果你能就此与我的老板会面,我会很高兴......
-
有什么理由不能在联合之外定义/typedef bk 结构吗?