Error no matching function

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct PayInfo
{
int hours; // Hours Worked
double payRate; // Hourly Pay Rate
};

struct PayRoll
{
int empNumber; // Employee number
string name; // Employee's name
double grossPay; // Gross Pay
PayInfo pay;
PayRoll (PayInfo& info, int num = 0, string Name = "", double gPay = 0.00)
{
empNumber = num;
name = Name;
grossPay = gPay;
pay.hours = info.hours;
pay.payRate = info.payRate;
}
};

int main()
{
PayRoll employee; // employee is a PayRoll structure.

// Get the employee's number.
cout << "Enter the employee's number: ";
cin >> employee.empNumber;

// Get the employee's name.
cout << "Enter the employee's name: ";
cin.ignore(); // To skip the '\n' character left in the input buffer
getline(cin, employee.name);

// Get the hours worked by the employee.
cout << "How many hours did the employee work? ";
cin >> employee.pay.hours;

// Get the employee's hourly pay rate.
cout << "What is the employee's hourly payRate? ";
cin >> employee.pay.payRate;

// Calculate the employee's gross pay.
employee.grossPay = employee.pay.hours * employee.pay.payRate;

// Display the employee data.
cout << "Here is the employee's payroll data:\n";
cout << "name: " << employee.name << endl;
cout << "Number: " << employee.empNumber << endl;
cout << "hours worked: " << employee.pay.hours << endl;
cout << "Hourly pay rate: " << employee.pay.payRate << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Gross Pay: $" << employee.grossPay << endl;
return 0;
}


When I try to compile it, it gives me a message saying "Error: no matching function for call to 'PayRoll::PayRoll()"
Define a default constructor for your PayRoll struct.
I thought I already did o_o

Didn't i define it through

"
PayRoll (PayInfo& info, int num = 0, string Name = "", double gPay = 0.00)
{
empNumber = num;
name = Name;
grossPay = gPay;
pay.hours = info.hours;
pay.payRate = info.payRate;
}
"

?
Last edited on
No, the only constructor you have is
PayRoll (PayInfo& info, int num = 0, string Name = "", double gPay = 0.00)
which needs at least one argument (a PayRoll&).

A default constructor needs to be callable with no arguments, so you need either PayRoll() or something along the lines of PayRoll(/* all optional arguments */).
I can't seem to figure a way to get rid another error "undefined reference to 'PayRoll::PayRoll()' " after i added the PayRoll(); as default.
Did you actually define the function?
how do i do that? i am really confused now >< recently introduced to structures
Topic archived. No new replies allowed.