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

前端 未结 5 2036
粉色の甜心
粉色の甜心 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:29

    It's legal, and if you're wondering why:

    Typically, unnamed arguments arise from the simplification of code or from planning ahead for extensions. In both cases, leaving the argument in place, although unused, ensures that callers are not affected by the change.

    Excerpt From: Bjarne Stroustrup. “The C++ Programming Language, Fourth Edition.”

提交回复
热议问题