【发布时间】:2011-10-25 06:59:12
【问题描述】:
我的函数中有一些参数接收和传递相同的值。我应该将所有参数变量命名相同吗?
例子:
// assume numMonth = 12
// assume numYear = 2000
int promptMonth(); // returns numMonth
int promptYear(); // returns numYear
int daysInMonth(int numMonth, int numYear); // numMonth and numYear will always
int daysInYear(int numYear); // be sent to these.
bool isLeapYear(int numYear); // daysInYear() and daysInMonth() call
// this function and send it numYear
// (which would be 2000 in this case).
是否应该将所有这些参数命名为相同,因为将相同的值传递给每个参数?
【问题讨论】:
-
“相同值”是什么意思?
-
我的意思是如果
numMonth在promptMonth()中被赋值为12,那么函数daysInMonth()中的参数变量numMonth也是12,因为来自promptMonth()的numMonth被传递给daysInMonth().所以变量numMonth是并且应该总是相同的值,在这种情况下是12。
标签: c++ coding-style parameter-passing