C++
文件 Employee.h
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
int age;
//C++ 字符串
//1 字符数组 char name[20]; #include <string.h> strcpy函数
//2 字符串 string #include <string>
string name;
char address;
public:
void sayHello();
};
Employee.cpp
#include <iostream>
#include <string>
#include "Employee.h"
using namespace std;
void Employee::sayHello() {
cout << "I love you ,chaochao" << endl;
}
TestEmployee.cpp
#include "Employee.h"
#include <iostream>
#include <string>
using namespace std;
//第一种
int main() {
Employee zhenglin;
zhenglin.age = 19;
zhenglin.name = "zhenglin";
zhenglin.sayHello();
return 0;
}
int main_01() {
//第二种
Employee *e1 = new Employee();
Employee *e2;
e2 = new Employee();
e1->age = 20;
e1->name = "yuxia";
e1->sayHello();
//第三种
Employee emp;
Employee *e3 = &emp;
e3->age = 21;
e3->name = "liyi";
e2->sayHello();
delete e1;
return 0;
}