class Student
{
public:
// 定義數據成員封裝函數setName()
void setName(string _name)
{
m_strName=_name;
}
// 定義數據成員封裝函數getName()
string getName(void)
{
return m_strName;
}
//定義Student類私有數據成員m_strName
private:
string m_strName;
};
{
public:
// 定義數據成員封裝函數setName()
void setName(string _name)
{
m_strName=_name;
}
// 定義數據成員封裝函數getName()
string getName(void)
{
return m_strName;
}
//定義Student類私有數據成員m_strName
private:
string m_strName;
};
Student() {
cout << "Student()" << endl;
}
explicit Student(string name) {
m_strName = name;
cout << "Student(string name)" << endl;
}
Student(const Student& stu) {
cout << "Student(const Student& stu)" << endl;
}
cout << "Student()" << endl;
}
explicit Student(string name) {
m_strName = name;
cout << "Student(string name)" << endl;
}
Student(const Student& stu) {
cout << "Student(const Student& stu)" << endl;
}
int main(void)
{
Student *stu = new Student("張晨飛");
Student *stu1 = new Student("張晨飛");
Student *stu2(stu1);
stu->setName("慕課網");
cout<<"學生名字:"<<stu->getName()<<endl;
cout<<"學生名字:"<<stu2->getName()<<endl;
delete stu2,stu,stu1;
stu=stu1=stu2=NULL;
return 0;
}
{
Student *stu = new Student("張晨飛");
Student *stu1 = new Student("張晨飛");
Student *stu2(stu1);
stu->setName("慕課網");
cout<<"學生名字:"<<stu->getName()<<endl;
cout<<"學生名字:"<<stu2->getName()<<endl;
delete stu2,stu,stu1;
stu=stu1=stu2=NULL;
return 0;
}
必須得把慕課網放到第一個輸出
class Student
{
public:
Student(){}
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;
};
class Student
{
public:
Student(){}
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;
};