真的通不過啊。。。。誰幫我看看
#include <iostream>
#include <string>
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;
? ? }
? ??
? ??
private:
//定義Student類私有數(shù)據(jù)成員m_strName?
? ? string m_strName;
};
int main()
{
? ? // 使用new關(guān)鍵字,實例化對象
? ? Student *str = new Student();
? ? // 設(shè)置對象的數(shù)據(jù)成員
str->setName("慕課網(wǎng)");
? ? // 使用cout打印對象str的數(shù)據(jù)成員
? ? cout<<str->getName()<<endl;
? ? // 將對象str的內(nèi)存釋放,并將其置空
delete str;
str=NULL;
return 0;
}
2016-07-25
在new屬性后如果是new Student[ ?],他的釋放對應(yīng)的才是 delete [ ]str。
2016-07-17
我想問的是:Student *str = new Student();是申請了一個內(nèi)存還是一個內(nèi)存塊,要是內(nèi)存塊的話后邊的內(nèi)存釋放不應(yīng)該是:delete []str; 雖然運行結(jié)果沒有影響。
2016-07-17
二樓回答有問題啊
2016-07-06
可以通過,沒有問題
2016-07-03
把cout << str->getName() << endl;換成cout << str->setName << endl;
2016-06-15
可以通過,應(yīng)該是閃了一下,你在 return 0; 前面加一行 system("pause"); 可以暫停屏幕