struct PayInfo
{
int hours;
double payRate;
};
struct PayRoll
{
PayRoll();
int empNumber;
string name;
double grossPay;
PayInfo pay;
};
void GrossPay(PayRoll employee[])
{
for (int i = 0; i < 3; i++)
{
employee[i].grossPay = employee[i].pay.hours *
employee[i].pay.payRate;
}
}
int main()
{
PayRoll employee[3]; //Problem is here.*****
for (int i = 0; i < 3; i++)
{
cout << "Enter the employee's number: " << endl;
cin >> employee[i].empNumber;
cout << "Enter the employee's name: " << endl;
cin.ignore();
getline(cin, employee[i].name);
cout << "How many hours did the employee work?" << endl;
cin >> employee[i].pay.hours;
cout << "What is the employee's hourly pay rate?" << endl;
cin >> employee[i].pay.payRate;
}
GrossPay(employee);
for (int j = 0; j < 3; j++)
{
cout << "Here is the employee's payroll data:\n";
cout << "name: " << employee[j].name << endl;
cout << "Number: " << employee[j].empNumber << endl;
cout << "hours worked: " << employee[j].pay.hours << endl;
cout << "Hourly pay rate: " << employee[j].pay.payRate << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Gross Pay: $" << employee[j].grossPay << endl;
}
return 0;
}
错误:对PayRoll :: PayRoll()的未定义引用 我现在该如何解决这个问题? 我试图用嵌套的结构制作一个数组。 从来没有使用那么多的结构,这就是我遇到很多困难的原因。
答案 0 :(得分:2)
为构造函数PayRoll::PayRoll
添加定义。
PayRoll::PayRoll() {}
如果你正在使用C ++ 11,你可以明确地默认它:
struct PayRoll
{
PayRoll() = default;
// ...