我有这个错误。 “错误:没有匹配的函数来调用'Employee::Employee()'”。当我编写有关“教员类”的构造函数时,出现此错误。
您能帮我解决这个问题吗?我求助:(。
还有2个类(class)。 “日期”和“人”。 “人员”是“雇员”的父类(super class)。
员工
#ifndef GK_EMPLOYEE_H
#define GK_EMPLOYEE_H
#include "GK_Person.h"
class Employee:public Person
{
public:
Employee(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,char* title,int salary,bool fulltime =true);// start refers to dynamic memory
//virtual ~Employee();
void SetTitle(char* title);
friend ostream& operator<<(ostream&,const Employee&);
friend class Faculty;
private:
char* m_title;
int m_salary;
bool m_fulltime;
Date* m_start;// date started working
};
#endif // GK_EMPLOYEE_H
员工文件
#include "GK_Employee.h"
Employee::Employee(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,char* title,int salary,bool fulltime/*=true*/){
m_name=name;
m_surname=surname;
m_sex=sex;
m_pob=pob;
m_dob=dob;
m_start=start;
m_title=title;
m_salary=salary;
m_fulltime=fulltime;
}
void Employee::SetTitle(char* title){
m_title = title;
}
学院
#ifndef GK_FACULTY_H
#define GK_FACULTY_H
#include "GK_Employee.h"
class Faculty :public Employee
{
public:
Faculty(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,int level,int salary,Date* dolat,bool fulltime = true);
//virtual ~Faculty();
char GetType() const{return'F';}
void Promote(Date* dt);
friend ostream& operator<<(ostream&,const Faculty&);
private:
Date* m_dolat;// date of last academic title owned
int m_level;// 0 for Dr., 1 for Ass.Prof.Dr., 2 for Assoc.Prof.Dr. and 3 for Prof.Dr.
};
#endif // GK_FACULTY_H
教员
#include "GK_Faculty.h"
Faculty::Faculty(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,int level,int salary,Date* dolat,bool fulltime/*= true*/){
}
最佳答案
由于Faculty
源自Employee
,因此您需要在Employee
构造函数中初始化Faculty
的成员。这必须通过调用Employee
的构造函数来完成。如果Employee
具有默认构造函数(即不带任何参数的构造函数),则编译器将为您隐式执行此操作。但是Employee
仅定义以下构造函数:
Employee(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,char* title,int salary,bool fulltime =true);// start refers to dynamic memory
编译器无法确定将哪些参数传递给此 Controller ,因此您需要自己从
Faculty
Controller 内部调用它。像这样:#include "GK_Faculty.h"
Faculty::Faculty(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,int level,int salary,Date* dolat,bool fulltime/*= true*/)
: Employee(name,surname,sex,pob,dob,start,"mytitle",salary,fulltime)
{
}
关于c++ - “error:no matching function call to …”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22510228/