第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

代碼出什么錯了???

#include <iostream>

#include <string>

#include <stdlib.h>

using namespace std;


/**

? * 定義類:Student

? * 數(shù)據(jù)成員:m_strName

? * 數(shù)據(jù)成員的封裝函數(shù):setName()、getName()

? */

class Student

{

public:

? ? // 定義數(shù)據(jù)成員封裝函數(shù)setName()

? ? void setName(string_name)

? ? {m_strName=_name;}

? ??

? ??

? ? // 定義數(shù)據(jù)成員封裝函數(shù)getName()

? ? string getName()

? ? {return m_strName;}

? ??

? ??

//定義Student類私有數(shù)據(jù)成員m_strName

private:

string m_strName;?


};


int main()

{

? ? // 使用new關(guān)鍵字,實例化對象

Student *str = new Student()

? ? // 設(shè)置對象的數(shù)據(jù)成員

str->setName("慕課網(wǎng)");

? ? // 使用cout打印對象str的數(shù)據(jù)成員

? ??

? ? // 將對象str的內(nèi)存釋放,并將其置空

cout<<str->getName()<<endl;

delete str;

str=NULL;

system("pause");

return 0;

}


正在回答

6 回答

?void setName(string_name)中的_前面要有一個空格

0 回復(fù) 有任何疑惑可以回復(fù)我~

Student *str = new Student()你這后面忘記加;

0 回復(fù) 有任何疑惑可以回復(fù)我~

你上面是_name ,下面是str,我上下統(tǒng)一后可以。你試試看。


0 回復(fù) 有任何疑惑可以回復(fù)我~

#include <iostream>

#include <string>

#include<stdlib.h>

using namespace std;


/**

? * 定義類:Student

? * 數(shù)據(jù)成員:m_strName

? * 數(shù)據(jù)成員的封裝函數(shù):setName()、getName()

? */

class Student

{

public:

? ? // 定義數(shù)據(jù)成員封裝函數(shù)setName()

? ? void setName(string _name)

? ? {

? ? ? ? m_strName=_name;

? ? ? ??

? ? }

? ??

? ??

? ? // 定義數(shù)據(jù)成員封裝函數(shù)getName()

? ? string getName()

? ? {

? ? ? ? return m_strName;

? ? }

? ??

? ??

//定義Student類私有數(shù)據(jù)成員m_strName

private:

?string m_strName;


};


int main()

{

? ? // 使用new關(guān)鍵字,實例化對象

Student *_name = new Student();

? ? // 設(shè)置對象的數(shù)據(jù)成員

_name->setName("慕課網(wǎng)");

? ? // 使用cout打印對象str的數(shù)據(jù)成員

? ??

? ? // 將對象str的內(nèi)存釋放,并將其置空

cout<<_name->getName()<<endl;

? ? delete _name;

? ? _name=NULL;

? ? system("pause");

return 0;

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

不行,還是出錯。

0 回復(fù) 有任何疑惑可以回復(fù)我~
?void?setName(string_name)
????{m_strName=_name;}
????……
????……
Student?*str?=?new?Student()

前面的sting_name要改成string _name,后面那句沒加分號。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
C++遠征之封裝篇(上)
  • 參與學(xué)習(xí)       103387    人
  • 解答問題       732    個

封裝--面向?qū)ο蟮幕?,本教程力求幫助小伙伴們即學(xué)即會

進入課程

代碼出什么錯了???

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號