I have noticed that when I create a new C++ class in Visual Studio, it writes down Foo(void)
and ~Foo(void)
as constructor and destructor templates instead of Foo()
and ~Foo()
. However, both versions seem to work. Is there a difference between both or does it not matter at all which version I use?

- 2,520
- 3
- 20
- 23
-
Someone already respond =) http://stackoverflow.com/questions/51032/is-there-a-difference-between-foovoid-and-foo-in-c-or-c – Dec 27 '14 at 20:28
-
This didn't show up in my search results because it is related to functions in general. I only saw it with constructors and destructors only until now. – Rapti Dec 27 '14 at 20:32
-
Don't worry, it's not an accusation that you should've searched better. :) Your question was fine. – Dec 27 '14 at 20:35
-
Someone gave me a downvote though ;) – Rapti Dec 27 '14 at 20:36
3 Answers
In C++, both are technically the same, as in "a function that takes no arguments"
For more info:
In C, however, Foo(void) is "a function that takes no arguments", but Foo() is "a function that takes unknown amount of arguments." These arguments are of an unspecified type.
Foo(void) is used across both languages with the same meaning.

- 431
- 4
- 16
Both are equivalent, so this is merely a choice of style. I prefer Foo()
because it involves less typing and it's what I've seen more often.
This question has actually been covered before on SO.
Apparently foo()
in C means "a function foo
taking an unspecified number of arguments of unspecified type" where in C++ it means "a function foo
taking no arguments."
-
1I also used that as you can see more easily whether the constructor takes arguments or not. I was just curious. – Rapti Dec 27 '14 at 20:27
Only when the constructor and destructor do not need any arguments, there are the same. Also Foo(void)
seems less frequently used.

- 1,402
- 2
- 11
- 18