<分区>
struct A
{
struct one
{
int c;
} details[MAX];
};
struct B
{
struct two
{
int a;
A::one b
} details[MAX];
};
下面使用了一个验证函数来验证结构 A 中结构的详细信息数组:
bool ValidateOne(struct one * ptr)
{
struct one * tmp[MAX];
for (int i = 0; i < MAX; ++i)
tmp[i] = ptr+i;
Validate(tmp[0]);
}
然后需要对结构 B 的详细信息数组进行验证: 我希望这样做:
bool ValidateTwo(struct two * ptr)
{
struct one * tmp[MAX];
for (int i = 0; i < MAX; ++i)
tmp[i] = &((ptr+i)->b);
Validate(tmp[0]);
//validate other stuff
};
Validate(struct one * ptrs[])
{
int count;
for (int i = 0; i < MAX; ++i)
count += ptrs[i]->a;
}
上面的代码行得通吗?