Reputation: 27
I am having this error. " error:no matching function to call 'Employee::Employee()' ". When i write a constructor about "faculty class" i am having this error. Can you help me with this issue? I am begging for help :( . There is 2 more classes. "Date" and "Person". "Person" is the super class of "Employee".
Employee.h
#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
Employee.cpp
#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;
}
Faculty.h
#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
Faculty.cpp
#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*/){
}
Upvotes: 2
Views: 851
Reputation: 206557
The subject of initialization is an important aspect of constructing objects in C++. When you construct a class, there has to be an unambiguous way of initializing all the base classes of the class as well as all the member data of the class.
If any of the base classes or member data cannot be initialized without using explicit initializers, the compiler will report an error unless you add code to initialize them in the initializer list.
Make sure you use the Employee
constructor with the right arguments in the initializer list of Faculty
constructor.
Change
Faculty::Faculty(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,int level,int salary, Date* dolat,bool fulltime/*= true*/) { }
to
Faculty::Faculty(char* name,char* surname,char* sex,char* pob, Date* dob,Date* start,int level,int salary, Date* dolat,bool fulltime/*= true*/) : Employe(name, surname, sex, pob, dob, start, level, salary, dolat, fulltime) { }
Upvotes: 1
Reputation: 4746
Since Faculty
derives from Employee
, you need to initalize the members of Employee
in your Faculty
constructor. This must be done by calling the constructor of Employee
. If Employee
had a default constructor (i.e. one without any parameters), then the compiler would do this implicitly for you. But Employee
only defines the following constructor:
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
The compiler cannot tell what arguments to pass to this c'tor, so you need to call it yourself from inside the Faculty
c'tor. Like this:
#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)
{
}
Upvotes: 4
Reputation: 218
Your Faculty constructor needs to explicitly construct Employee since it has no default constructor:
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, ....) {
}
Upvotes: 2