我在一个类中有一个枚举数据类型。我想从 main 内部设置/分配它的值。我的代码看起来像
class pet
{
public:
enum species { bird,cat,dog,rat,horse };
enum demands { food,water,companionship };
demands demand;
species petSpecies;
float waterLevel = 100;
float foodLevel = 100;
float Happiness = 100;
//Species are not initialized in the class and have to be initialized separately in main
string name;
//And a bunch of functions here and there
};
在我的主要功能中,我使用 vector 创建了一组宠物,每只宠物都有自己的名字和种类。事实证明,给宠物设定一个物种是很困难的。
我该怎么做?
最佳答案
vector_pets[i].petSpecies = pet::horse;
应该做你想做的事。
关于c++ - 数组枚举和输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43413185/