【发布时间】:2011-01-22 12:47:09
【问题描述】:
在:http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/
代码如下:
// Declare a DateStruct variable
DateStruct sToday;
// Initialize it manually
sToday.nMonth = 10;
sToday.nDay = 14;
sToday.nYear = 2020;
// Here is a function to initialize a date
void SetDate(DateStruct &sDate, int nMonth, int nDay, int Year)
{
sDate.nMonth = nMonth;
sDate.nDay = nDay;
sDate.nYear = nYear;
}
// Init our date to the same date using the function
SetDate(sToday, 10, 14, 2020);
这样做的目的是什么
DateStruct &sDate
函数签名中的参数,尤其是我在函数体中看不到它的使用?
谢谢。
【问题讨论】:
-
请读一本书。
-
这是在文章的另一个地方写的:“......我们需要将结构本身作为第一个参数传递给 SetDate() 函数。否则,SetDate() 不会知道什么我们想要处理的 DateStruct。”。