Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why put void in params?

Tags:

c++

What's the reason for putting void inside of the params?

Why not just leave it blank?

void createLevel(void);  void createLevel(); 
like image 761
RoR Avatar asked Apr 07 '11 20:04

RoR


People also ask

What is void * params?

It means the param of type void* (reference to a void), which is the size of a memory location . You can reference any memory location with this, which in practice anything.

Is void parameter necessary?

main(void) will be called without any parameters. If we try to pass it then this ends up leading to a compiler error.

What is the point of a void function?

When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal." If a pointer's type is void* , the pointer can point to any variable that's not declared with the const or volatile keyword.

When passing parameters What does void mean?

Void is used only in method signatures. For return types it means the method will not return anything to the calling code. For parameters it means no parameters are passed to the method.


2 Answers

The void in the parenthesis are from C. In C a function with empty parentheses could have any number of parameters. In C++ it doesn't make any difference.

like image 147
halfdan Avatar answered Oct 02 '22 17:10

halfdan


void in function argument lists is a relict of the past (C). In C++, you should leave the parentheses empty. Of course you can keep the void if it makes you happy.

In C, if you declare a function with empty parentheses, the meaning is that the number of parameters is unknown. void can be used to make it explicit that no parameters are expected.

like image 31
Alexander Gessler Avatar answered Oct 02 '22 17:10

Alexander Gessler