指針那塊老有問題,有大神能夠解答問題嗎?
#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()
{
}
2019-05-29
通過了
#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()
{
}