我对编程还比较陌生,即使进行了彻底的研究,我也无法解决这个问题。
我想通过一个对象[定义为变量类型union
]检查是否可以与用户输入的新对象进行比较,因为输入的对象是否在这个特定的集合中,但是总是弹出两个错误:
“一元‘*’(具有‘Object’)的无效类型参数”
bool is_element_of(Object items, SET*S)
{
LIST*scan = *S;
int p = 0;
while (S != NULL)
{
if (*scan->item == items)
p = 1;
scan = scan->next;
}
if (p == 1)
return true;
else
return false;
}
这是结构定义以及对象的 union :
typedef struct object
{
union
{
char c;
char t[OSIZE];
unsigned long int h[OSIZE];
unsigned int i;
float f;
long double j[OSIZE];
int type;
} TYPE;
} Object;
typedef struct list1
{
Object item;
struct list1*next;
} LIST;
typedef LIST*SET;
最佳答案
if (*scan->item == items)
scan->item
是一个对象,而不是指针。所以你不能取消引用它。
关于c - "invalid type argument of unary ' *' C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20762373/