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;
};
#include <iostream>
#include <string>
using std::cout;
using std::endl;
namespace Student {
public:
int m_strName;
int m_iAge;
};
int main(void) {
Student stu;
stu.m_strName = "imooc";
stu.m_iAge = 2;
cout << stu.m_strName << " " << stu.m_iAge << endl;
return 0;
}
#include <string>
using std::cout;
using std::endl;
namespace Student {
public:
int m_strName;
int m_iAge;
};
int main(void) {
Student stu;
stu.m_strName = "imooc";
stu.m_iAge = 2;
cout << stu.m_strName << " " << stu.m_iAge << endl;
return 0;
}
public:
void setName(string _name)
{m_strName = _name;}
string getName()
{return m_strName;}
private:
string m_strName;
};
int main()
{ Student *str = new Student();
str->setName("慕课网");
cout << str->getName() <<endl;
delete str;
str = NULL;
return 0;}
void setName(string _name)
{m_strName = _name;}
string getName()
{return m_strName;}
private:
string m_strName;
};
int main()
{ Student *str = new Student();
str->setName("慕课网");
cout << str->getName() <<endl;
delete str;
str = NULL;
return 0;}