請問哪里錯了
#include <iostream>
#include <string>
using namespace std;
/**
?* 定義類:Student
?* 數(shù)據(jù)成員:m_strName
?* 無參構(gòu)造函數(shù):Student()
?* 有參構(gòu)造函數(shù):Student(string _name)
?* 拷貝構(gòu)造函數(shù):Student(const Student& stu)
?* 析構(gòu)函數(shù):~Student()
?* 數(shù)據(jù)成員函數(shù):setName(string _name)、getName()
?*/
class Student
{
? ? public:
? ? Student()
? ? {?
? ? ? ? m_strName="";
? ? ? ? //cout<<"Student()"<<endl;
? ? }
? ? Student(string _name) ?
? ? {
? ? ? ? m_strName=_name;
? ? ? ?// cout<<" Student(string _name) "<<endl;
? ? }
? ? Student(const Student& stu);
? ? {
? ? ? ? //cout<<"Student(const Student& stu)"<<endl;
? ? }
? ? ~Student(){};
? ? void setName(string);
? ? string getname();
? ?private:
? ? ? string ?m_strName;
};
void Student::setName(string _name)
? ? {
? ? ? ? m_strName=_name;
? ? }
string Student::getName()
? ? {
? ? ? ? return m_strName;
? ? }
int main(void)
{
? ? // 通過new方式實(shí)例化對象*stu
? ? Student *stu = new Student;
? ? // 更改對象的數(shù)據(jù)成員為“慕課網(wǎng)”
stu->setName("慕課網(wǎng)");
? ? // 打印對象的數(shù)據(jù)成員
cout<< stu->getName() << endl;
delete stu;
stu=NULL;
return 0;
}
2018-07-18
1.string getname();中Name應(yīng)注意大小寫
2.Student *stu = new Student();中實(shí)例化對象應(yīng)帶()
2018-07-04
可能類外定義識別不了,我試了直接把set和get的函數(shù)坐在類里面,可以正常運(yùn)行。
2018-07-04
getname();定義不對,之后n全是大寫
2018-07-04
拷貝構(gòu)造函數(shù)變量后面沒有;
析構(gòu)函數(shù)后面為什么要加;?實(shí)例化對象new Student()