|
本帖最后由 ioulex 于 2020-4-8 15:19 编辑
定义了三个类,CStudent、Xiao_student、Zhong_student,Xiao_student 继承CStudent,Zhong_student继承Xiao_student。
CStudent 类的头文件
#include <iostream>
#include <string.h>
using namespace std;
class CStudent
{
public:
char* p_name;
char sex;
int num;
int age;
static int master;
void print_name();
CStudent();
CStudent(const char* t_name, char t_sex, int t_num, int t_age);
~CStudent();
};
CStudent 类的CPP文件
#include "CStudent.h"
int CStudent::master = 1;
void CStudent::print_name()
{
cout << p_name << endl;
}
CStudent::CStudent()
{
}
CStudent::CStudent(const char* t_name, char t_sex, int t_num, int t_age)
{
int n_len = strlen(t_name) + 1;
p_name = new char[n_len];
memset(p_name, 0, n_len);
strcpy_s(p_name, n_len, t_name);
sex = t_sex;
num = t_num;
age = t_age;
}
CStudent::~CStudent()
{
cout << "析构函数被调用了" << endl;
}
小学生类的头文件
#include <iostream>
#include <string.h>
using namespace std;
class Xiao_student : public CStudent
{ //错误提示行,错误提示:"CStudent":未定义基类
public:
int yuwen_score;
int shuxue_score;
Xiao_student();
~Xiao_student();
};
小学生类的CPP文件
#include "Xiao_student.h"
Xiao_student::Xiao_student()
{
}
Xiao_student::~Xiao_student()
{
cout << "小学生被析构了" << endl;
}
中学生类的头文件
#include <iostream>
#include <string.h>
using namespace std;
class Zhong_student:public Xiao_student
{ //错误提示行,错误提示:"Xiao_student":未定义基类
public:
int wuli_score;
int huaxue_score;
Zhong_student();
~Zhong_student();
};
中学生类的CPP文件
#include "Zhong_student.h"
Zhong_student::Zhong_student()
{
}
Zhong_student::~Zhong_student()
{
cout << "中学生被析构了" << endl;
}
不太懂未定义基类这个问题是出自哪里,网上好多人说,头文件中不要互相引用,我也遵从了这个原则。
两条错误提示
错误提示:"Xiao_student":未定义基类
错误提示:"Xiao_student":未定义基类
编译环境:vs2019
|
上一篇: 指针遍历字符串下一篇: 求大佬帮忙解决一下问题
|