[英]Data structure and algorithm in C++
I have these two functions:我有这两个功能:
void MakeNull_List(List L){
L->Last=0;
}
void Empty_List(List L){
return L.Last==0;
}
So, can anyone explain this code for me?那么,谁能为我解释一下这段代码? What is the difference between
L->Last
and L.Last
? L->Last
和L.Last
什么L.Last
?
I hope that this code does NOT come from your lecturer, otherwise you should look for another one...我希望这个代码不是来自你的讲师,否则你应该寻找另一个......
Sadly this code doesn't make sense because it is wrong!可悲的是,这段代码没有意义,因为它是错误的! But I think you meant the following:
但我认为你的意思是:
void MakeNull_List(List *L){ //* added
L->Last=0;
}
bool Empty_List(List L){ //changed to bool
return (L.Last==0); //Please also use brackets here
}
The first function sets the last element to 0 (NULL) whathever sense it should make?!?第一个函数将最后一个元素设置为 0(NULL),不管它应该有什么意义?!? The second function checks whether the last element is 0 (NULL) or not.
第二个函数检查最后一个元素是否为 0 (NULL)。
And your actual question: ->
is used to Access properties of a pointer to an object and .
而您的实际问题:
->
用于访问指向对象的指针的属性和.
accesses the properties directly of the object.直接访问对象的属性。 For more info read here
欲了解更多信息,请阅读此处
Then you access object by variable or reference you should address to it fields by .
然后您通过变量或引用访问对象,您应该通过
.
. . Then you have a pointer to object you should previously dereference it.
然后你有一个指向对象的指针,你应该以前取消引用它。 So, you can write
(*ptr).someField
or ptr->someField
.所以,你可以写
(*ptr).someField
或ptr->someField
。
I think, you miss *
in void MakeNull_List(List *L)
definition.我认为,您在
void MakeNull_List(List *L)
定义中错过了*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.