Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;		
		}
Posted
Updated 7-Feb-22 11:09am
v7
Comments
Tony Hill 6-Feb-22 14:28pm    
It would help if you could show the definition of the Employee class.
Mehboob Shaukat 6-Feb-22 14:37pm    
Sir, I uploaded the overall class, please check this
Tony Hill 6-Feb-22 15:20pm    
I tried your code and it works OK and seems to do what is expected.

I did not get any [Error] no matching for call to 'Employee(const char[12], const char[16], int, int, int)'
Mehboob Shaukat 6-Feb-22 15:25pm    
Thank you sir! But on my PC this error is showing. And now I download an application for a mobile cop compiler this shows an error missing return type for the function. What is your opinion, I'll need to reinstall my software or need to download a new copy of the software of Devcpp? Please suggest me.
Patrice T 6-Feb-22 14:49pm    
And you think you can tell us the error message or it is secret ?

After adding includes and namespace and correcting the typo everything compiles fine.
C++
// typo: Employee != Epmloyee
Employee(string id, string name, int year, int month, int date)
 
Share this answer
 
v2
Comments
jeron1 7-Feb-22 17:22pm    
'typo' D'oh! Good catch.
CPallini 8-Feb-22 2:03am    
Good catch, indeed.
C++
Employee e2(string("BC210207935"), String("Mehboob Shaukat"), 2021, 04, 01);
should work. Your compiler isnt automatically creating a string out of your char array. I guess some multibyte settings or do have do declare the ctor to public?
 
Share this answer
 
The compiler defaults to not having C++11 features available. This seems to be the problem in your case.

You should do these

To adjust the settings:
• Under the Tools menu choose “Compiler Options”.
• In the window that comes up you will see tabs for “General”, “Settings”, “Directories” and “Programs”.
• Choose the settings tab.
• In the next set of tabs that come up choose “Code Generation”.
• The last line should say “Language Standard (-std).
• On the right side of that line click on the down arrow.
• In the list box that comes up choose “ISO C++ 11”.
• Press “OK”.

above came from following Unknown Error - C++ Forum[^]

Further elaborations can be found below

string - Dev-C++ "to_string is not a member of std" error - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900