【发布时间】:2019-02-21 10:33:45
【问题描述】:
为了解释我的问题,我在下面发布了一个示例。这种形式的代码未经测试,因此可能存在一些语法错误。由于我必须使用集成电路中的许多寄存器,它们的地址可以重新映射,因此创建如下所示的结构将非常有用。创建这些结构有什么技巧吗?由于此示例无法按我想要的方式工作,因为 foo 需要 Country 对象,并且 Country::Europe::Italy 作为参数无效。
// I want to create a structure like this
class myClass {
public:
class Country {
enum class Europe {
England,
France,
Germany,
Italy
};
enum class Asia {
China,
Japan
};
};
// Here I want to make sure, that the method is only
// called with a Country element and e.g. Italy should
// behave like a Country object. Actually it should behave
// as if it is derived from Country.
int foo(Country c);
};
int main() {
myClass myC();
// Exemplary call of the method foo
myC.foo(myClass::Country::Europe::Italy);
}
【问题讨论】:
-
enum Class不是一个类。所以不能从Country类派生出来。
标签: class c++11 data-structures struct enums