[英]Casting void * to a struct which is a pointer?
我有一个链接列表,其中每个节点的格式如下:
struct queueItem
{
struct carcolor *color;
int id;
};
typedef struct queueItem *CustDetails;
我想运行以下功能:
extern void mix(struct carcolor *v);
但是,该函数在其中运行:
void foo(void *v) //v should be the pointer to the dequeued queueItem
{
//do other stuff
mix(v->color);
}
这给出了错误:
request for member ‘color’ in something not a structure or union
当函数原型为void foo(void *v)
时,如何访问struct carcolor *color
?
我试过强制转换(struct queueItem) v
但是没有用。
您需要转换为结构的指针。
mix(((struct queueItem *)v)->color);
在这种情况下,我想做的就是获取一个本地指针并使用它
void foo(void *v) //v should be the pointer to the dequeued queueItem
{
struct queueItem *localpointer = v;
//do other stuff
mix(localpointer->color);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.