亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

指針那塊老有問題,有大神能夠解答問題嗎?

#include <iostream>

#include <string>

#include<stdlib.h>

using namespace std;


class Student

{

public:

// 定義數據成員封裝函數setName()

Student();

Student(string name);

void setName(string _name);

string getName();

Student(const Student &tea);

~Student();

private:

string m_strName;

};


int main(void)

{

// 通過new方式實例化對象*stu

Student *stu = new Student();

// 更改對象的數據成員為“慕課網”

stu->m_str_Name = "慕課網";

// 打印對象的數據成員

cout << "stu->m_strName>" << endl;

return 0;

}


Student::Student() :m_strName(name)

{

m_strName = "JIM";

}


void Student::setName(string _name)

{

m_strName = _name;

}

string Student::getName()

{

return m_strName;

}

Student::Student(const Student&tea)

{

cout << "Student(const Student&tea)" << endl;

};

Student::~Student()

{

}


正在回答

1 回答

通過了

#include <iostream>

#include <string>

#include<stdlib.h>

using namespace std;


class Student

{

public:

// 定義數據成員封裝函數setName()

Student();

Student(string name);

void setName(string _name);

string getName();

Student(const Student &tea);

~Student();

private:

string m_strName;

};


int main(void)

{

// 通過new方式實例化對象*stu

Student *stu = new Student();

// 更改對象的數據成員為“慕課網”

stu->setName("慕課網");

// 打印對象的數據成員

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

system("pause");

return 0;

}


Student::Student()

{

m_strName = "JIM";

}


void Student::setName(string _name)

{

m_strName = _name;

}

string Student::getName()

{

return m_strName;

}

Student::Student(const Student&tea)

{

cout << "Student(const Student&tea)" << endl;

};

Student::~Student()

{

}


0 回復 有任何疑惑可以回復我~

舉報

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

封裝--面向對象的基石,本教程力求幫助小伙伴們即學即會

進入課程

指針那塊老有問題,有大神能夠解答問題嗎?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號