最新回答 / KellyCayne
不一定是string型,看函數最后返回的數據類型,如果返回的是int數據,則get函數是int類型,只有get函數返回string型的數據時,它才是string類型
2019-11-06
初始化列表操作const也沒啥用啊,第一次實例化const定義的值就固定了,再次實例化同一類時,const定義的值永遠是第一次的
2019-10-27
int main(void)
{
// 通過new方式實例化對象*stu
Student *stu = new Student;
// 更改對象的數據成員為“慕課網”
stu->setName("慕課網");
// 打印對象的數據成員
stu->getName();
return 0;
}
{
// 通過new方式實例化對象*stu
Student *stu = new Student;
// 更改對象的數據成員為“慕課網”
stu->setName("慕課網");
// 打印對象的數據成員
stu->getName();
return 0;
}
using namespace std;
class Student
{
public:
Student(){}
Student(string _name):m_strName(_name){}
Student(const Student& stu){}
~Student(){}
void setName(string _name){m_strName = _name;}
string getName(){cout << m_strName << endl; }
private:
string m_strName;
};
class Student
{
public:
Student(){}
Student(string _name):m_strName(_name){}
Student(const Student& stu){}
~Student(){}
void setName(string _name){m_strName = _name;}
string getName(){cout << m_strName << endl; }
private:
string m_strName;
};