`f(void)` meaning no parameters in C++11 or C?

后端 未结 5 808
忘掉有多难
忘掉有多难 2021-01-07 17:58

In C++11 the following function declaration:

int f(void);

means the same as:

int f();

A pa

5条回答
  •  不要未来只要你来
    2021-01-07 18:24

    In C++, there is no difference. However, this is inherited from C, where int f() mean "function which can take any number of arguments of any types" and int f(void); specifies functions that takes no arguments.

    Edit As Angew pointed out, in C, f() means "function whose parameters are unknown at this point." It does not mean it can take any number of arguments - close to that would be f(T arg, ...), where arg is at least one named parameter before ..., which accepts at least one argument, arg (as pointed by @hvd).

提交回复
热议问题