gpt4 book ai didi

c - 错误: 'void*' is not a pointer-to-object type

转载 作者:行者123 更新时间:2023-11-30 20:55:37 25 4
gpt4 key购买 nike

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

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

任何人都可以对此提出建议吗?

最佳答案

data 的类型为 void*,因此 data->emp 的类型为 void,其中你不能真正拥有,更不用说分配了。

关于c - 错误: 'void*' is not a pointer-to-object type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31931677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com