如何创建单个类的多个实例?

时间:2021-04-14 05:33:37

标签: class oop if-statement inheritance main

尊敬的关心, 我想向用户询问员工人数,然后根据员工人数输入数据。但问题是这段代码无法做到这一点。请指导我错误或我遗漏的地方。我将不胜感激。

int main() {
    int size;
    cout << "How many employee data you want to enter? ";
    cin >> size;

    cout << endl;
    employee* EMP[size];

    int i = 0;
    char choice;
    char input;

    for(int i = 0; i < size; i++) {
        cout << endl;
        cout << "Enter Choice: S for salariedEmp, H for hourlyemp: " << endl;
        cin >> choice;
        cout << endl;
        if(choice == 'S') {
            EMP[i] = new salariedEmp();
        } else if(choice == 'H') {
           EMP[i] = new hourlyemp();
        }
        EMP[i++]->calculateSalary();
    }

    for (int i = 0; i < size; i++) {
        EMP[i]->Print();
    }
    system("pause");
    return 0;
}

0 个答案:

没有答案
相关问题