Why is a function without argument identifiers valid in C++?

前端 未结 5 2034
粉色の甜心
粉色の甜心 2021-02-06 22:05

Given a function in C++ with arguments that are only types and have no identifiers,

 void foo1(int, int, int){cout << \"called foo1\";}

I

5条回答
  •  青春惊慌失措
    2021-02-06 22:10

    Yes. It is legal in C++.

    C++11 n3337 standard 8.4.1(p6) Function definitions:

    Note: Unused parameters need not be named. For example,

    void print(int a, int) {
        std::printf("a = %d\n", a);
    }
    

    C++14 standard:

    [ 8.3.5.11] An identifier can optionally be provided as a parameter name; if present in a function definition , it names a parameter (sometimes called “formal argument”). [Note: In particular, parameter names are also optional in function definitions and names used for a parameter in different declarations and the definition of a function need not be the same.]

提交回复
热议问题