Can an unnamed parameter of function have a default value?

后端 未结 4 1391
北荒
北荒 2021-02-20 00:36

Is the following code legal in C++?

void f(void* = 0)
{}

int main()
{
    f();
}

Which page of the C++ standard states that this usage is lega

4条回答
  •  既然无缘
    2021-02-20 01:14

    Yes, it's perfectly legal. An obvious example is found in N3485 8.3.6 Default Arguments/4:

    [Example: the declaration

    void point(int = 3, int = 4);  
    

    declares a function that can be called with zero, one, or two arguments of type int.

提交回复
热议问题