Need help compiling a payroll program

I think I'm pretty close. I'm getting an error "no default constructor exists for class "Payroll"". I'm wondering if I have to put in another constructor in the .cpp file, but I thought it was taken care of in the header file.

Epayroll.cpp
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
  #include "stdafx.h"
#include "Payroll.h"
#include <iostream>
#include <fstream>

using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{
	Payroll  total;

	int i, h;
	double r, p;

	//Get ID#
	cout << "Enter employee's ID number: ";
	cin >> i;
	total.set_id(i);

	//Get hourly rate
	cout << "Enter employee's rate of pay: ";
	cin >> r;
	total.set_rate(r);

	//Get hours
	cout << "How many hours did the employee work?: ";
	cin >> h;
	total.set_hours(h);

	//calculate and display
	total.get_pay(p);
	cout << "Your information" << endl;
	cout << total;

	return 0;



}.

Payroll.h:
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
#ifndef PAYROLL_H
#define PAYROLL_H

#include <iostream>
using namespace std;

class Payroll;




ostream &operator << (ostream &, Payroll &x);
istream &operator >> (istream &, Payroll &y);

class Payroll{
private:
	int id;
	double rate;
	int hours;
	double pay;
public:
	Payroll(int i, double r, int h, double p)
	{
		id = i;
		rate = r;
		hours = h;
		pay = p;
	}
	
	void set_id(int i)
	{
		id = i;
	}
	
	void set_rate(double r)
	{
		rate = r;
	}
	
	void set_hours(int h)
	{
		hours = h;
	}
	
	double get_pay(double p)
	{
		return hours * rate;
	}

	
	
	friend ostream &operator<<(ostream &, const Payroll &);
	friend istream &operator>>(istream &, Payroll &);
		
};

#endif
Payroll total; tries to call Payroll::Payroll() constructore but there is no one avaliable. You have to either define it, or use already defined one instead.
There's something about this I'm just not getting. This can be pretty frustrating. lol
Bump, because I have a class in a couple hours and could use the help.
What exactly you do not getting?

1
2
3
4
Payroll total; //This is variable declaration and initialization. 
               //It have to call object constructor. As you did not provided any parameters,
               //constructor without parameters is called. But it does not exist. Hence the error.
               //Either provide that constructor or call constructor you defined. 
I'm completely frustrated. Here's what I have after modifying.

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
#ifndef PAYROLL_H
#define PAYROLL_H

#include <iostream>
using namespace std;


class Payroll
{
private:
	int id;
	double rate;
	double hours;
	double pay;

public:
	Payroll(int, double, double, double)
	{
		id = i;
		rate = r;
		hours = h;
		pay = p;
	}
		
	void set_id(int)
	{
		id = i;
	}
	
	void set_rate(double)
	{
		rate = r;
	}
	
	void set_hours(double)
	{
		hours = h;
	}
	
	double get_pay(double) const
	{
		return hours*rate;
	}
	
	friend ostream &operator<<(ostream &output, const Payroll &p);
	friend istream &operator>>(istream &input, Payroll &p);
		
};

#endif 


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
#include "stdafx.h"
#include "Payroll.h"
#include <iostream>
#include <fstream>

using namespace std;



ostream &operator << (ostream &output, const Payroll &p){
	output << "Your ID# is : " << p.id << endl;
	output << "Your rate of pay is: $" << p.rate << endl;
	output << "Your hours worked was: " << p.hours << endl;
	output << "Your pay is: $" << p.pay << endl;
	return output;
}

istream &operator >> (istream &input, Payroll &p){
	input >> p.set_id >> p.set_rate >> p.set_hours;
	return input;
}

	int _tmain(int argc, _TCHAR* argv[])
	{
		cout << "Enter ID#, Rate of Pay, and Hours Worked:" << endl;
		Payroll total(int i, double r, double h, double p);
		cin >> total;
		cout << total;
		

		return 0;



	
}


Getting these errors when I try to compile:

Error
1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) line 19

2 IntelliSense: no operator ">>" matches these operands
operand types are: std::istream >> Payroll (int i, double r, double h, double p) line 27
Last edited on
Payroll total(int i, double r, double h, double p); Declares a function taking int and three doubles and returning Payroll.
Topic archived. No new replies allowed.