C++言語における引数を取らない関数のパラメータリスト。f1とf2の関数シグネチャは同一。
int f1(); int f2(void); int (*pf)(void) = f1; // OK int (&rf)() = f2; // OK
パラメータリスト中でvoid型を使えるのは“空のパラメータリスト”を表す場合のみ。
int h(int, void); // NG: void int g(int, void*); // OK: void*
N3337 8.3.5/p4, C.1.7より該当箇所を引用。
If the parameter-declaration-clause is empty, the function takes no arguments. The parameter list
(void)
is equivalent to the empty parameter list. Except for this special case,void
shall not be a parameter type (though types derived fromvoid
, such asvoid*
, can).
Change: In C++, a function declared with an empty parameter list takes no arguments. In C, an empty parameter list means that the number and type of the function arguments are unknown.
Example:int f(); // means int f(void) in C++ // int f( unknown ) in CRationale: This is to avoid erroneous function calls (i.e., function calls with the wrong number or type of arguments).