Search code examples
c++programming-languagesmethods

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 of the * was for, and if there is any difference between public void *foo() and public void foo()?

***This is C++ code here!


Solution

  • 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.