Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function prototype in header files

Tags:

c++

I wanted to know what the difference between the following two declarations is in header files I have come across both these styles

void some_method(int);

and the second style is :

void some_method(int a);

Does one style have any benefit over the other. To me one style just does not have the name of a variable and the name of the variable has to be implemented in the accompanying cpp file.

like image 240
MistyD Avatar asked Jun 20 '13 09:06

MistyD


2 Answers

There is no difference in functionality, but I often use parameter names as a form of documentation, like so:

void verbTheThing(int verbId, int thingId);

When I have nothing valuable to add, I just don't add it:

int max(int, int);
like image 94
Magnus Hoff Avatar answered Oct 04 '22 15:10

Magnus Hoff


The main concern is consistency. Pick one and stick to it. I prefer the second personally because parameter names can describe functionality and code that's self-documenting is better than the alternative.

like image 32
Luchian Grigore Avatar answered Oct 04 '22 17:10

Luchian Grigore