1 继承
CStudent
CStudent_college : public CStudent
{
};
大学生-----子类 派生类
学生-------父类 基类
不完整的代码,只是框架:
//main.cpp
#include
#include
using namespace std;
int main()
{
CStudent_college college1(1001,"zhangsan","计算机系","软件专业");
college1.print_student();
return 0;
}
基类----CStudent
//Student.h
class CStudent
{
public:
CStudent();
virtual ~CStudent();
};
//Student.cpp
CStudent::CStudent()
{
}
CStudent::~CStudent()
{
}
派生类----CStudent_college
//Student_college.h
#include "Student.h"
class CStudent_college : public CStudent
{
char *department;
char *profe;
public:
CStudent_college();
virtual ~CStudent_college();
CStudent_college(int number,char *name,char *department,char *profe);
void print_student();
};
//Student_college.cpp
// Student_college.cpp: implementation of the CStudent_college class.
//
//
#include "Student_college.h"
//
// Construction/Destruction
//
CStudent_college::CStudent_college()
{
}
CStudent_college::~CStudent_college()
{
}
CStudent_college::CStudent_college(int number,char *name,char *department,char *profe):CStudent(number,name)
{
department=new char[strlen(department)+1];
strcpy(this->department,department);
profe=new char[strlen(profe)+1];
strcpy(this->profe,profe);
}
void CStudent_college::print_student()
{
cout<
return;
}