C ++错误“主表达式

时间:2014-02-24 06:01:48

标签: c++

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];

    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;
}

我不知道如何解决我的错误。

  

错误:在'employee'之前预期的primary-expression

但除此之外,我不确定如何将构造函数放在嵌套结构中。我也不确定如何用数组

定义结构

* * *编辑

现在说

  

错误:对'PayRoll :: PayRoll()'

的未定义引用

2 个答案:

答案 0 :(得分:1)

要将变量作为函数参数传递,只需指定变量的名称:

GrossPay(employee);

答案 1 :(得分:1)

GrossPay(PayRoll employee[]);     //Problem is here.

作为函数参数传递时,仅使用变量名:

GrossPay(employee);