当前位置: 代码迷 >> 综合 >> C++,类的拷贝构造函数,类的申明和实现分开写, 语法练习
  详细解决方案

C++,类的拷贝构造函数,类的申明和实现分开写, 语法练习

热度:39   发布时间:2024-01-19 15:36:57.0

 

// 类的申明和实现分开写在不同的文件中

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
  相关解决方案