My class declaration and function isn't taking the 5 arguments that it needs.

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.

Here is my class declaration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
# ifndef EMPLOYEE_H
# define EMPLOYEE_H
# include <string>
using namespace std;


/*CLASS DECLARATION - Member variables & function prototypes*/
class Employee
{
	private:   //private attributes
	   string name;
	   string idNumber;
	   string department;
	   string position;
	   double yearsWorked;

	public:   //function prototypes
		void setName(string);
        void setIdNumber(string);
		void setDepartment(string);
		void setPosition(string);
		Employee(double);//constructor to initialize yearsWorked to 0
		bool setYearsWorked(double);
		string getName() const;
		string getIdNumber() const;
		string getDepartment() const;
		string getPosition() const;
		double getYearsWorked() const;
};
#endif



here is my function implementation file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# include "Employee.h"
# include <iostream>
# include <string>
using namespace 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;
}


and here is my main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# include <iostream>
# include <string>
# include "Employee.h"
using namespace std;

/*********************************************************
					MAIN
*********************************************************/

int main()
{
	Employee e1("Jenny Jacobs",8990,"Accounting","President",15);
	Employee e2("Myron Smith",7571,"IT","Programmer",5);
	Employee e3("Chris Raines",6873,"Manufacturing","Engineer",30);

	cout << "Name\t\tID Number\t\tDepartment\t\tPosition\t\tYears Worked"
		 << "\n----\t\t--------\t\t----------\t\t--------\t\t------------" << endl;
	cout << e1.getName() << "\t\t" << e1.getIdNumber() << "\t\t" << e1.getDepartment() << "\t\t" << e1.getPosition() << "\t\t" << e1.getYearsWorked() << endl;
	cout << e2.getName() << "\t\t" << e2.getIdNumber() << "\t\t" << e2.getDepartment() << "\t\t" << e2.getPosition() << "\t\t" << e2.getYearsWorked() << endl;
	cout << e3.getName() << "\t\t" << e3.getIdNumber() << "\t\t" << e3.getDepartment() << "\t\t" << e3.getPosition() << "\t\t" << e3.getYearsWorked() << endl;
	
	system("PAUSE");
	return 0;
}

Your constructor takes a single variable of type double. You're trying to pass 3 strings and two integers.
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.
Last edited on
@ Ispil should I then make the constructor pass the 3 strings and 2 integers?
@vlad I did make the years into the double. did you not read my code?
@new2c

Vlad was saying not to have year as a double.

I think you should investigate these things:

- Use an initialiser list in the constructor.

- Avoid having set functions - they are really bad. We had a huge discussion about this here:

http://www.cplusplus.com/forum/lounge/101305/


The proper use of constructors will mean you don't need any set functions.

- You can get rid of the get functions by having a print function in your class.

Hope all goes well.
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Something
{
public:
    int variable;
    Something( void ) : variable( 3 ){}
}

int main()
{
    Something s;
    std::cout << s.variable << std::endl;
    ++s.variable;
    std::cout << s.variable << std::endl;
}


*Edit oh sorry didn't realize that he also suggested the print function in the class
Last edited on
Topic archived. No new replies allowed.