In my code I am using the get, set and Employee constructor for getting and take the employee data for that I am creating an one .h file and two .cpp file. While executing these files i am getting error.
So my first .h file is emp.h:
#include<iostream>
class Employee
{
private:
std::string emp_Name,emp_ID,emp_Address;
public:
Employee(std::string name, std::string id, std::string address):emp_Name(name),
emp_ID(id),emp_Address(address)
{
}
void setempname(std::string name);
void setempid(std::string id);
void setempage(std::string address);
std::string getempname();
std::string getempid();
std::string getempaddress();
};
My first .cpp file is emp.cpp
#include "emp.h"
void Employee::setempname(std::string name)
{
emp_Name=name;
}
void Employee::setempid(std::string id)
{
emp_ID=id;
}
void Employee::setempage(std::string address)
{
emp_Address=address;
}
std::string Employee::getempname()
{
return emp_Name;
}
std::string Employee::getempid()
{
return emp_ID;
}
std::string Employee::getempaddress()
{
return emp_Address;
}
My second .cpp file is Main.cpp:
#include "emp.h"
int main()
{
Employee emp[2];
emp[0]= Employee ("Rohi","E345","Clk");
return 0;
}
The Error I am getting is:
g++ emp.cpp Main.cpp
Main.cpp: In function ‘int main()’:
Main.cpp:4:23: error: no matching function for call to ‘Employee::Employee()’
Employee emp[2];
^
In file included from Main.cpp:1:
emp.h:7:3: note: candidate: ‘Employee::Employee(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’
Employee(std::string name, std::string id, std::string address):emp_Name(name),
^~~~~~~~
emp.h:7:3: note: candidate expects 3 arguments, 0 provided
emp.h:2:7: note: candidate: ‘Employee::Employee(const Employee&)’
class Employee
^~~~~~~~
emp.h:2:7: note: candidate expects 1 argument, 0 provided
emp.h:2:7: note: candidate: ‘Employee::Employee(Employee&&)’
emp.h:2:7: note: candidate expects 1 argument, 0 provided
So Anyone please help me to solve these error.
Aucun commentaire:
Enregistrer un commentaire