Why add void to method parameter list

后端 未结 4 1941
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 06:53

I\'ve seen methods with the following signature:

void foo (void);

They take no argument, however I\'m wondering whether doing this is usefu

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 07:17

    This is a holdover from older versions of C, where foo() meant "a function with an unknown number of parameters" and foo(void) means "a function with zero parameters." In C++, foo() and foo(void) both mean "a function with zero parameters", but some people prefer the second form because it is more explicit.

提交回复
热议问题