請(qǐng)指點(diǎn)這個(gè)代碼錯(cuò)在哪里?
#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 = "";
? ? }
? ??
? ? Student(string _name)
? ? {
? ? ? ? m_strName = _name;
? ? }
? ??
? ? Student(const Student& stu){}
? ??
? ? ~Student(){}
? ??
? ? void setName(string _name){m_strName = _name}
? ??
? ? string getName(){return m_strName}
private:
? ? string m_strName;
};
int main(void)
{
? ? // 通過new方式實(shí)例化對(duì)象*stu
? ? Student *stu = new Student();
? ? // 更改對(duì)象的數(shù)據(jù)成員為“慕課網(wǎng)”
stu->setName("慕課網(wǎng)");
? ? // 打印對(duì)象的數(shù)據(jù)成員
cout << stu->getName() << endl;
? ? delete stu;
? ? stu = NULL;
return 0;
}
2015-12-02
c++setName ?getName 函數(shù)可以不寫分好號(hào),不寫不會(huì)報(bào)錯(cuò),但是函數(shù)里面的語句要寫上分號(hào),否則會(huì)報(bào)錯(cuò)
2015-09-14
setName ?getName 函數(shù)的語句后都少寫了分號(hào)
2015-09-14
請(qǐng)?jiān)趦?nèi)聯(lián)函數(shù)里把語句的;寫上