如何使用枚举元素创建对象

时间:2017-01-24 13:51:13

标签: c++ enums

我的枚举由类名组成。例如:

class A{};
class B{};

class example{
    enum set_of_classnames {A,B}

};

我想在示例类中创建类AB的对象。使用迭代器或for循环可以通过获取枚举元素来为A和B创建对象吗?

1 个答案:

答案 0 :(得分:0)

不确定

set_of_classnames choice = choose(); // class can be chosen at runtime
if(choice == A) {
    class A object;
} else if(choice == B) {
    class B object;
}

此代码可以在循环中使用。