I have to write a program that takes three employees that displays their name, id nmber, department, position and years worked. It has to be done using a class and header. I got all of my programing done but when I compile i get an error saying "error C2661: 'Employee::Employee' : no overloaded function takes 5 arguments"
I'm not sure how to fix it.
# include "Employee.h"
# include <iostream>
# include <string>
usingnamespace std;
/*EMPLOYEE MEMBER FUNCTION DEFINITIONS */
/****************************************************************************
Employee::Employee(double)
This constructior takes one argument passed to it when an object is instantiated and assigs those values to the yearsWorked members.
if the argument passed in is negative, the constructor sets them to zero
*****************************************************************************/
Employee::Employee(double years)
{
if(years >=0)
yearsWorked = years;
else
yearsWorked = 0;
}
/*****************************************************************************
Employee :: setYearsWorked
If the argument passed to the setYearsWorked function is zero or greater it is copied into the member variable length and true is returned. If the argument is negative, the value of yearsWorked remains unchanged and false is returned.
*****************************************************************************/
bool Employee::setYearsWorked(double years)
{
bool validData;//local variable
if(years >= 0)//if yearsWorked is positive data is valid
{ yearsWorked = years;
validData=true;}
else//else data is invalid
{ validData=false;}
return validData;//return to calling program whether or not data is valid
}
/*****************************************************************************
Employee::setName
This function initializes the name attribute to an empty string("")
*****************************************************************************/
void Employee::setName(string)
{
name="";
}
/*****************************************************************************
Employee::setIdNumber
This function initializes the idNumber attribute to an empty string("")
*****************************************************************************/
void Employee::setIdNumber(string)
{
idNumber="";
}
/*****************************************************************************
Employee::setDepartment
This function initializes the department attribute to an empty string("")
*****************************************************************************/
void Employee::setDepartment(string)
{
department="";
}
/*****************************************************************************
Employee::setPosition
This function initializes the position attribute to an empty string("")
*****************************************************************************/
void Employee::setPosition(string)
{
position="";
}
/*****************************************************************************
Employee::getName
This function returns the value that is in the private member name
*****************************************************************************/
string Employee::getName() const
{
return name;
}
/*****************************************************************************
Employee::getIdNumber
This function returns the value that is in the private member idNumber
*****************************************************************************/
string Employee::getIdNumber() const
{
return idNumber;
}
/*****************************************************************************
Employee::getDepartment
This function returns the value that is in the private member department
*****************************************************************************/
string Employee::getDepartment() const
{
return department;
}
/*****************************************************************************
Employee::getPosition
This function returns the value that is in the private member position
*****************************************************************************/
string Employee::getPosition() const
{
return position;
}
It is not clear why are you asking the question because the error message is clear enough. Why do you not read error messages? Also is not a good idea to define the number of years as having type double.
As TheIDeasMan has already said use an initializer list. Constructor() : variable( value ) , variable2( value2 ) {}
Also if you do not intend on modifying them maybe make them a const? You can initialize const values. You should also get rid of the get functions( imo set/get are bad practice. ) **Instead make them public variables instead of private** if you intend on them being modified which it looks like you are you can also get the output by using a print function