C:
cout << stu->getName() << endl;
delete stu;
return 0;
}
cout << stu->getName() << endl;
delete stu;
return 0;
}
B:
private:
string m_strName="世间第一帅气人";
};
Student::Student(string name) :m_strName(name) {}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
int main(void) {
Student *stu = new Student;
stu->setName("慕课网");
private:
string m_strName="世间第一帅气人";
};
Student::Student(string name) :m_strName(name) {}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
int main(void) {
Student *stu = new Student;
stu->setName("慕课网");
A:
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student(string name) ;
Student(const Student & stuc) {};
Student() {};
~Student() {};
void setName(string name);
string getName();
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student(string name) ;
Student(const Student & stuc) {};
Student() {};
~Student() {};
void setName(string name);
string getName();
头文件B:
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax = 1;
};
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax = 1;
};
2019-01-26
头文件A:
#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白", int Age = 1, int Max = 100);//初始化构造函数 构造函数——用以初始化
Student(const Student &stu);//拷贝构造函数
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白", int Age = 1, int Max = 100);//初始化构造函数 构造函数——用以初始化
Student(const Student &stu);//拷贝构造函数
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
2019-01-26
源2B:
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
int Student::getMax() {
return m_iMax;
}
void Student::setName(string name) {
m_strName = name;
}
string Student::getName() {
return m_strName;
}
void Student::setAge(int Age) {
m_iAge = Age;
}
int Student::getAge() {
return m_iAge;
}
int Student::getMax() {
return m_iMax;
}
2019-01-26
源2A:
#include"标头.h"
Student::Student(string name, int Age, int Max) :m_strName(name), m_iAge(Age), m_iMax(Max) { cout << "you used initialization_code"<<endl; } //初始化列表
Student::Student(const Student & stu) { cout << "you used copy_code"<<endl; }//拷贝构造函数
#include"标头.h"
Student::Student(string name, int Age, int Max) :m_strName(name), m_iAge(Age), m_iMax(Max) { cout << "you used initialization_code"<<endl; } //初始化列表
Student::Student(const Student & stu) { cout << "you used copy_code"<<endl; }//拷贝构造函数
2019-01-26
源1:
#include"标头.h"
int main() {
Student *str = new Student;//初始化——指针方式
Student stu1("小白", 12, 150);//初始化
str->setName("慕课网");
Student stu2 = stu1;//测试拷贝函数部分
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
#include"标头.h"
int main() {
Student *str = new Student;//初始化——指针方式
Student stu1("小白", 12, 150);//初始化
str->setName("慕课网");
Student stu2 = stu1;//测试拷贝函数部分
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
2019-01-26