[英]Is there a “right” way to Prototype functions in C++?
I was taught to do: 我被教导要做:
functionReturn function(dataType_of_parameter)
While more and more I have been seeing 我越来越看到
functionReturn function(dataType_of_parameter parameter_identifier)
Both suggestions are right ways to declare a function. 这两个建议都是声明函数的正确方法。 The argument names are optional and make no difference to the compiler except in the function definition. 参数名称是可选的,除了函数定义外,对编译器没有影响。
The advantage of naming function arguments in forward declarations is that a programmer can deduce the the purpose of the argument. 在前向声明中命名函数参数的优点是程序员可以推断出参数的用途。 Consider for example void copy(T* source, T* dest)
versus void copy(T*, T*)
. 考虑例如void copy(T* source, T* dest)
与void copy(T*, T*)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.