开发者

Why would you ever want to create a method called *foo() instead of just foo()?

I see this in other people's code sometimes:

public void *foo() {
...
}

public void bar() {
...
}

but I never understood what the meaning开发者_StackOverflow社区 of the * was for, and if there is any difference between public void *foo() and public void foo()?

***This is C++ code here!


public void *foo() is a public function that returns a void pointer (which can be anything essentially). More documentation on pointers can be found here: http://www.cplusplus.com/doc/tutorial/pointers/ (specifically the void pointer section).

public void *foo() and public void* foo() are the same and the position of * is purely a style thing (although the style can have implications when used elsewhere).

public void foo() is a public function that returns nothing.


The spacing is confusing you. void *foo(int) is the same thing as void* foo(int). The former returns void *, the latter does not return anything. Some people prefer to attach the '*' to the type precisely to avoid this confusion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜