求各位解答一下我這個哪里有問題了。。
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
/**
? * 定義類:Student
? * 數據成員:m_strName
? * 數據成員的封裝函數:setName()、getName()
? */
class Student
{
public:
? ? // 定義數據成員封裝函數setName()
? ? void setName(string str)
? ? {
? ? ? ? m_strName = str;
? ? }
? ??
? ??
? ? // 定義數據成員封裝函數getName()
? ? string getName()
? ? {
? ? ? ? return m_strName;
? ? }
? ??
? ??
//定義Student類私有數據成員m_strName
private:
? ? string m_strName;
};
int main()
{
? ? // 使用new關鍵字,實例化對象
Student *str = new student();
? ? // 設置對象的數據成員
str->setName("慕課網");
? ? // 使用cout打印對象str的數據成員
? ? cout << str->getName() << endl;
? ? // 將對象str的內存釋放,并將其置空
system("paulse");
delete str;
str = NULL;
return 0;
}
2019-05-06
Student *str = new student() ? 后面的應該是大寫吧 ?你試一試?