错误:'void *'不是指向对象的指针类型

时间:2015-08-11 01:16:30

标签: c

我在我的程序中尝试以下代码并收到错误。

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

任何人都可以就此提出建议。

1 个答案:

答案 0 :(得分:2)

data的类型为void*,因此data->emp的类型为void,您无法真正拥有,更不用分配。