如下代码:
#include <iostream>
using namespace std;
class CStudent
{
public:
static int noOfStudents;
CStudent& nextStudent()
{
noOfStudents ++;
return *this;
}
};
int CStudent::noOfStudents = 0;
void fn(CStudent& s)
{
cout << s.nextStudent().noOfStudents << endl;
}
void main()
{
CStudent ss;
fn(ss);
}
我想知道:
CStudent& nextStudent()
{
noOfStudents ++;
return *this;
}
返回对象引用的函数一般用在什么地方?它有什么作用? |