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
  • 162,933
  • 34
  • 285
  • 360
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
  • 72,057
  • 21
  • 174
  • 247
2

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

gheese
  • 1,122
  • 1
  • 10
  • 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,315
  • 7
  • 21
  • 31