在codeblocks上可以運行,求幫忙看下問題出在哪里
#include <iostream>
#include <string>
using namespace std;
/**
?* 定義類:Student
?* 數據成員:m_strName
?* 無參構造函數:Student()
?* 有參構造函數:Student(string _name)
?* 拷貝構造函數:Student(const Student& stu)
?* 析構函數:~Student()
?* 數據成員函數: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方式實例化對象*stu
? ? Student *stu = new Student();
? ? // 更改對象的數據成員為“慕課網”
stu->setName("慕課網");
? ? // 打印對象的數據成員
cout<<stu->getName()<<endl;
delete stu;
stu=NULL;
return 0;
}
2017-04-29
好像是沒錯的,有的時候代碼即使是對的提交上去也反饋是錯的。同學你刷新刷新,換一天再提交試試,我剛才提交了你的代碼是通過的……
2017-06-15
private 下東西少了不少。
2017-06-15
// 通過new方式實例化對象*stu
? ? Student *stu = new Student();
2017-06-15