#include"string"
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白",int Age=1,int Max=100);//构造函数初始化
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax
#include"iostream"
using namespace std;
class Student {
public:
Student(string name = "小白",int Age=1,int Max=100);//构造函数初始化
void setName(string name);
string getName();
void setAge(int Age);
int getAge();
int getMax();
private:
string m_strName;
int m_iAge;
const int m_iMax
2019-01-25
Student::Student(string name,int Age,int Max) :m_strName(name), m_iAge(Age),m_iMax(Max){} //初始化列表
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;
}
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;
}
2019-01-25
DEMO1:
#include"标头.h"
int main() {
Student *str = new Student;
Student stu1("小白", 12, 150);
str->setName("慕课网");
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("慕课网");
cout << stu1.getName() << " \t " << str->getAge() << "\t" << str->getMax();
delete str;
str = NULL;
return 0;
}
2019-01-25
class Student {
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();
delete str;
str = NULL;
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();
delete str;
str = NULL;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(){
class student {
public:
string m_strName = "王发财";
int m_iAge = 199;
}stu;
stu.m_iAge = 2;
stu.m_strName = "慕课网";
cout << stu.m_iAge <<endl<< stu.m_strName << endl;
}
#include <string>
using namespace std;
int main(){
class student {
public:
string m_strName = "王发财";
int m_iAge = 199;
}stu;
stu.m_iAge = 2;
stu.m_strName = "慕课网";
cout << stu.m_iAge <<endl<< stu.m_strName << endl;
}
p[i]->这个确实不符合常规 数组是特殊的指针 当指针加上【】 其性质是和数组是一样的 下面那位说p[i]->可以连用的 你是真恶心 不懂就乱指点 诱导他人理解错误真可耻
2018-12-17