Different parameter name in function prototype

前端 未结 1 671
青春惊慌失措
青春惊慌失措 2021-01-12 08:07

I found a program which uses different parameters in function prototyping and declaring, so I made a basic program.

#include 
using namespace         


        
相关标签:
1条回答
  • 2021-01-12 08:40

    Yes, the name of parameters used in declaration and definition doesn't have to be the same. Instead, the type of parameters (and order), should be the same. In fact, parameter names are not necessary especially in function declaration, even in definition they also could be omitted if you don't use them.

    [dcl.fct]/13:

    (emphasis mine)

    An identifier can optionally be provided as a parameter name; if present in a function definition ([dcl.fct.def]), it names a parameter. [ 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. If a parameter name is present in a function declaration that is not a definition, it cannot be used outside of its function declarator because that is the extent of its potential scope ([basic.scope.proto]). — end note ]

    And [dcl.fct]/8:

    The return type, the parameter-type-list, the ref-qualifier, the cv-qualifier-seq, and whether the function has a non-throwing exception-specification, but not the default arguments ([dcl.fct.default]) or the exception specification ([except.spec]), are part of the function type.

    Note that the parameter-type-list, not including their names, is part of the function type.

    0 讨论(0)
提交回复
热议问题