c++ enum and using them to input from user

前端 未结 3 1995
时光说笑
时光说笑 2021-02-08 05:34

I have an enum in my code that is the following: enum Status {In-Active, Active};. A status object is passed to a Person object as a parameter, so I wa

3条回答
  •  不思量自难忘°
    2021-02-08 05:54

    • Enum objects are being parsed at compile time and it can only contain constant integer values.

    • Person p(name, age, status); //Here without using status object you should send a value directly like "In-Active" or "Active". So there would be no input from the user regarding th status field.

    enum Status {InActive, Active};

    • Here Status is a enum class and any object created would contain values "Inactive" or "Active". If you try to assign some other value you would get an compiler error.

    Status status;

    • Here status is an enum object created and it contains garbage value.

    cout << "Enter status: "; cin >> status;

    • Here you are asking user for an input for an enum object which is totally invalid for the compiler.

提交回复
热议问题