class Date
{
public:
Date(int year = 2018, int month = 6, int day = 23)
: _year(year)
, _month(month)
, _day(day)
{}
constint& GetDay()const//被const修饰后,this指针类型从Date* const this-->const Date* const this
{
return _day;
}
private:
int _year;
int _month;
int _day;
};
int main()
{
Date d1;
cout << d1.GetDay() << endl;
}
class Date
{
public:
Date(int year = 2018, int month = 6, int day = 23)
: _year(year)
, _month(month)
, _day(day)
{}
constint& GetDay()const//被const修饰后,this指针类型从Date* const this-->const Date* const this
{
_day++;
return _day;
}
private:
int _year;
int _month;
mutable int _day;
};