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;
};
区别一:C语言的const是定义了一个const变量,该变量只具备读的功能,而不具备写的功能。 C++的const是定义了一个常量。int main(){ const int a = 10; int arr[a];//在c++中,因为a已经是常量,但在c中仍是变量,会报错}再看下面的代码#include &amp;amp;lt;stdio.h&amp;amp;gt;//c...