指針那塊老有問(wèn)題,有大神能夠解答問(wèn)題嗎?
#include <iostream>
#include <string>
#include<stdlib.h>
using namespace std;
class Student
{
public:
// 定義數(shù)據(jù)成員封裝函數(shù)setName()
Student();
Student(string name);
void setName(string _name);
string getName();
Student(const Student &tea);
~Student();
private:
string m_strName;
};
int main(void)
{
// 通過(guò)new方式實(shí)例化對(duì)象*stu
Student *stu = new Student();
// 更改對(duì)象的數(shù)據(jù)成員為“慕課網(wǎng)”
stu->m_str_Name = "慕課網(wǎng)";
// 打印對(duì)象的數(shù)據(jù)成員
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
通過(guò)了
#include <iostream>
#include <string>
#include<stdlib.h>
using namespace std;
class Student
{
public:
// 定義數(shù)據(jù)成員封裝函數(shù)setName()
Student();
Student(string name);
void setName(string _name);
string getName();
Student(const Student &tea);
~Student();
private:
string m_strName;
};
int main(void)
{
// 通過(guò)new方式實(shí)例化對(duì)象*stu
Student *stu = new Student();
// 更改對(duì)象的數(shù)據(jù)成員為“慕課網(wǎng)”
stu->setName("慕課網(wǎng)");
// 打印對(duì)象的數(shù)據(jù)成員
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()
{
}