// 类的申明和实现分开写在不同的文件中
main.cpp
// main.cpp
#include <iostream>
#include <string>
#include "student.h"
using namespace std;
int main(void)
{
Student x1("柳絮飘",22,"学明路115号");
Student x2(x1);
// ----
return 0;
}
//类的头文件 student.h
// student.h
#include <string>
using namespace std;
class Student
{
public:
// 存
void setname(string s);
void setage(int y);
void setaddress(string add);
// 取
string getname();
int getage();
string getaddress();
Student & show();
Student(string name,int age,string address);
~Student();
Student(Student& copyfun);
protected:
private:
string name;
int age;
string address;
};
// 类的实现 student.cpp
//student.cpp
#include "student.h"
#include <io