![](/img/trans.png)
[英]C++ - Is there a difference between declaring a function's return value as void/void* when used in a thread?
[英]linked list c++ difference between void function and return this
我有一个关于编码 2 styles 之间的区别的问题:
void *addfirst (int data){
head = new Node(int data, head);
return;
}
第二个是:
LinkedList *addfirst (int data){
head = new Node(int data, head);
return this;
}
我的教授说现在大多数人都喜欢第二种选择,但我不知道与第一种相比有什么优势吗?
void *addfirst (int data){ head = new Node(int data, head); return; }
声明 function 以返回类型为void*
的 object。 function 什么也不返回。 程序的行为是未定义的。
LinkedList *addfirst (int data){ head = new Node(int data, head); return this; }
这个 function 确实返回 object。行为定义明确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.