0

I've recently switched from Java to learning C++, I'm a newbie to this language so I need your help :)

What's the difference?

void method(void) {

}

and

void method() {

}

Many thanks!

zxcv
  • 1
  • 1

4 Answers4

6

In C++, there's no difference -- they both mean a function that takes zero arguments.

In C, () means a function that takes any number of arguments, while (void) means a function that takes zero arguments.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
2

None. There was a difference in C (void means no parameters and nothing means an unknown number of parameters) but not in C++; they are the same.

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
2

in C++ there is no difference, they are the same

gheese
  • 1,170
  • 1
  • 11
  • 17
1

C++ is the exact same, however in C it means a function that takes any # of arguments. It is really just a stylistic matter that is up to you.

MarJamRob
  • 3,395
  • 7
  • 22
  • 31