Hey everyone I hope you all are well.
I'm solving a problem that is my classwork but I facing this error continuously.
Quote:
[Error] no matching for call to 'Employee(const char[12], const char[16], int, int, int)'
This is appearing in the main function. Kindly anyone tells me about this!
Error is showing in the following block.
And in this line.
Employee e2("BC210207935", "Mehboob Shaukat", 2021, 04, 01);
I read many answer of other people's but can not get proper solution.
My over all employee class is:
class Employee
{
private:
string empId;
string empName;
int joiningYear;
int joiningMonth;
int joiningDate;
public:
Employee()
{
empId = "<<EMPTY>>";
empName = "<<EMPTY>>";
joiningYear = 0;
joiningMonth = 0;
joiningDate = 0;
}
Epmloyee(string id, string name, int year, int month, int date)
{
empId=id;
empName=name;
joiningYear=year;
joiningMonth=month;
joiningDate=date;
}
void setValues(Employee *emp2)
{
empId=emp2->empId;
empName=emp2->empName;
joiningYear=emp2->joiningYear;
joiningMonth=emp2->joiningMonth;
joiningDate=emp2->joiningDate;
}
string getId()
{
return empId;
}
string getName()
{
return empName;
}
int getYear()
{
return joiningYear;
}
int getMonth()
{
return joiningMonth;
}
int getDate()
{
return joiningDate;
}
void display(Employee emp)
{
cout<<"ID: "<<emp.getId()<<endl;
cout<<"Name: "<<emp.getName()<<endl;
cout<<"Joining Year: "<<emp.getYear()<<endl;
cout<<"Joining Month: "<<emp.getMonth()<<endl;
cout<<"Joining Date: "<<emp.getDate()<<endl;
}
};
int main()
{
Ply e1;
Ply e2("BC210207935", "Mehboob Shaukat", 2021, 04, 01);
cout<<"Ply 1 Using default Constructor:"<<endl;
e1.display(e1);
cout<<"Ply 2 Using Perameterized constructor:"<<endl;
e2.display(e2);
cout<<"Ply 1 having Ply 2 copied data member values"<<endl;
e1.setValues(&e2);
e1.display(e1);
return 0;
}
now I'm using online compiler to do this but facing same error. compiler link is:
https://www.onlinegdb.com/online_c++_compiler[
^]
and error is:
Quote:
21 | Epmloyee(string id, string name, int year, int month, int date)
| ^
main.cpp: In member function ‘int Employee::Epmloyee(std::string, std::string, int, int, int)’:
main.cpp:28:3: warning: no return statement in function returning non-void [-Wreturn-type]
28 | }
| ^
main.cpp: In function ‘int main()’:
main.cpp:69:60: error: no matching function for call to ‘Employee::Employee(const char [12], const char [16], int, int, int)’
69 | Employee e2("BC210207935", "Mehboob Shaukat", 2021, 04, 01);
| ^
main.cpp:13:3: note: candidate: ‘Employee::Employee()’
13 | Employee()
| ^~~~~~~~
main.cpp:13:3: note: candidate expects 0 arguments, 5 provided
main.cpp:3:7: note: candidate: ‘Employee::Employee(const Employee&)’
3 | class Employee
| ^~~~~~~~
main.cpp:3:7: note: candidate expects 1 argument, 5 provided
main.cpp:3:7: note: candidate: ‘Employee::Employee(Employee&&)’
main.cpp:3:7: note: candidate expects 1 argument, 5 provided
What I have tried:
int main()
{
Employee e1;
Employee e2("BC210207935", "Mehboob Shaukat", 2021, 04, 01);
cout<<"Employee 1 Using default Constructor:"<<endl;
e1.display(e1);
cout<<"Employee 2 Using Perameterized constructor:"<<endl;
e2.display(e2);
cout<<"Employee 1 having Employee 2 copied data member values"<<endl;
e1.setValues(&e2);
e1.display(e1);
return 0;
}