我在我的程序中尝试以下代码并收到错误。
abc rec; //abc is a struct which is having data member with void*.
rec.data = (price*)malloc(sizeof(price)); //rec.data is a void* and price is a structure
emp * e = (emp *)calloc(2, sizeof(emp)); // emp is a struct, which is member of struct price.
e[0].a = 1;
rec.data->emp = e; // error: 'void*' is not a pointer-to-object type
任何人都可以就此提出建议。
答案 0 :(得分:2)
data
的类型为void*
,因此data->emp
的类型为void
,您无法真正拥有,更不用分配。