在復(fù)習(xí)初始化參數(shù)列表的時(shí)候,把數(shù)據(jù)成員max設(shè)置const修飾,不僅不能再構(gòu)造函數(shù)內(nèi)部進(jìn)行修改,即使設(shè)置一個(gè)setter函數(shù)也不能進(jìn)行修改了
2020-12-19
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
string m_strName;
int m_iAge;
};
int main()
{
Student stu;
stu.m_strName = "慕課網(wǎng)";
stu.m_iAge = 2;
cout <<stu.m_strName << " " <<stu.m_iAge<< endl;
return 0;
}
#include <string>
using namespace std;
class Student
{
public:
string m_strName;
int m_iAge;
};
int main()
{
Student stu;
stu.m_strName = "慕課網(wǎng)";
stu.m_iAge = 2;
cout <<stu.m_strName << " " <<stu.m_iAge<< endl;
return 0;
}