本文介绍了&是什么QUOT;在东西请求成员的*******'不是一个结构或联合"意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有什么这个错误意味着什么?

Is there an easy explanation for what this error means?

request for member '*******' in something not a structure or union

我遇到它,我一直在学习C的时候好几次,但我没有得到一个线索,就是这个意思。

I've encountered it several times in the time that I've been learning C, but I haven't got a clue as to what it means.

推荐答案

这也恰好如果你想,当你有一个指针来访问一个实例,反之亦然:

It also happens if you're trying to access an instance when you have a pointer, and vice versa:

struct foo
{
  int x, y, z;
};

struct foo a, *b = &a;

b.x = 12;  /* This will generate the error, should be b->x or (*b).x */

由于在评论中指出,这是可以做痛苦的,如果有人去和的typedef SA指针,即包括 * 在typedef,像这样:

As pointed out in a comment, this can be made excruciating if someone goes and typedefs a pointer, i.e. includes the * in a typedef, like so:

typedef struct foo* Foo;

由于那么你得到code,它的看起来的喜欢它的处理情况,而实际上它在处理指针:

Because then you get code that looks like it's dealing with instances, when in fact it's dealing with pointers:

Foo a_foo = get_a_brand_new_foo();
a_foo->field = FANTASTIC_VALUE;

请注意如何上面看起来好像它应该写成 a_foo.field ,但由于将失败是结构体的指针。我强烈推荐的针对 的typedef :在C指针ED指针是很重要的,不要隐藏你的星号。让他们闪耀。

Note how the above looks as if it should be written a_foo.field, but that would fail since Foo is a pointer to struct. I strongly recommend against typedef:ed pointers in C. Pointers are important, don't hide your asterisks. Let them shine.

这篇关于&是什么QUOT;在东西请求成员的*******'不是一个结构或联合"意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:44