如何访问在枚举类中定义的结构属性。
错误为“错误:'e'不是类,命名空间或枚举”

enum class pay_type
{
    hourly, salary
};

struct employee
{
    string first_name;
    string last_name;
    pay_type pay_kind;
    double pay_unit_amount;
};

istream& operator >> (std::istream& is, employee& e)
{

    is >> e.first_name;
    is >> e.last_name;
    if (e.pay_kind == pay_type::hourly && e.pay_kind == pay_type::salary)
    {
        is >> e::pay_kind;
    }

    is >> e.pay_unit_amount;
    return is;
}

最佳答案

您需要的是:

std::istream& operator >> (std::istream& is, employee& e)
{

    is >> e.first_name;
    is >> e.last_name;

    // Read the pay kind as an integer.
    // Check to make sure that the value is acceptable.

    int payKind;
    is >> payKind;
    if (payKind == pay_type::hourly || payKind == pay_type::salary)
    {
       e.pay_kind = static_cast<pay_type>(payKind);
    }
    else
    {
       // Deal with error condition
    }

    is >> e.pay_unit_amount;
    return is;
}

09-25 21:01