the*_*est 1 c c++ pointers linked-list
我正在尝试实现通用链表.节点的结构如下 -
typedef struct node{
void *data;
node *next;
};
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试为数据分配地址时,假设例如对于int,例如 -
int n1=6;
node *temp;
temp = (node*)malloc(sizeof(node));
temp->data=&n1;
Run Code Online (Sandbox Code Playgroud)
如何从节点获取n1的值?如果我说 -
cout<<(*(temp->data));
Run Code Online (Sandbox Code Playgroud)
我明白了 -
`void*' is not a pointer-to-object type
Run Code Online (Sandbox Code Playgroud)
当我为其分配int的地址时,无效指针是否被转换为int指针类型?