0 c++
我被教导要做:
functionReturn function(dataType_of_parameter)
Run Code Online (Sandbox Code Playgroud)
虽然我越来越多地看到了
functionReturn function(dataType_of_parameter parameter_identifier)
Run Code Online (Sandbox Code Playgroud)
这两个建议都是宣布函数的正确方法.参数名称是可选的,除了函数定义之外,对编译器没有任何区别.
在前向声明中命名函数参数的优点是程序员可以推断出参数的目的.考虑例如void copy(T* source, T* dest)对比void copy(T*, T*).