Why are function argument names unimportant in c++ declarations?

六月ゝ 毕业季﹏ 提交于 2019-12-05 06:57:59

The compiler only needs to know what kind of arguments the method requires. It's unimportant for the compiler how you call them.

The compiler needs to know the argument types for several reasons:

  • Decide which method to use if there are several methods with the same method name
  • Decide whether the input parameters are valid
  • Decide whether the parameters need to be casted
  • Decide how to generate the CODE to call the method and handle the response

However, I suggest to use the first header version. It helps other developers (and yourself) to use the functions and know what parameters have which meaning.

Parameter names aren't part of the function signature. Unless you use them, you don't need to have names even in the function implementation.

Because the names don't affect anything the compiler does outside the function.

The only reason I can think about that version 1 is better is readability. They are ignored as they don't matter for the compiler.

..because when the headers are included in other modules it only needs the types to generate the correct code. The names ae often useful and convenient, but nopt absolutely necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!