[英]Some clarification needed in the struct pointers
我对以下代码有疑问,
我的功能如下
void deleteNode(struct myList ** root)
{
struct myList *temp;
temp = *root;
...//some conditions here
*root = *root->link; //this line gives an error
*root = temp->link; //this doesnt give any error
}
所以这两行之间有什么区别,对我来说看起来是一样的。错误是,
error #2112: Left operand of '->' has incompatible type 'struct myList * *'
谢谢 :)
这里的问题是,“->”运算符比“ *”运算符绑定更紧密。 所以你的第一条声明:
// what you have written
*root->link;
正在评估以:
// what you're getting - bad
*(root->link);
而不是:
// what you want - good
(*root)->link;
由于root是指向指针的指针,因此->运算符对此没有任何意义,因此会出现错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.