- -更新 - -
在我的项目中包含头文件和 cpp 文件时遇到问题,所以这里是文件:Person.h
#ifndef PERSON_H
#define PERSON_H
class Person {
private:
string firstName;
string lastName;
long NID;
public:
Person();
void toString();
string get_firstName() {
return firstName;
}
string get_lastName() {
return lastName;
}
long get_NID() {
return NID;
}
};
#endif
扩展 Person Teacher.h 的教师
#include "Person.h"
#include <iostream>
#ifndef TEACHER_H
#define TEACHER_H
class Teacher : public Person {
private:
int avg_horarium;
public:
Teacher();
void toString();
int get_avg_horarium() {
return avg_horarium;
}
};
#endif
然后是 Teacher.cpp:
#include "Teacher.h"
using namespace std;
Teacher::Teacher() : Person() {
cout << "Enter average monthly horarium: ";
cin >> avg_horarium;
}
void Teacher::toString() {
Person::toString();
cout << "Average monthly horarium: " << avg_horarium;
}
扩展 Person 的另一个类是 Student,由于它与老师相似,我不会在这里发布它。我的问题是我做错了什么才能在屏幕截图上显示所有这些错误:http: //s14.postimage.org/45k08ckb3/errors.jpg