枚举范围 [英] Enumeration Scope

查看:159
本文介绍了枚举范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速的问题:

如果我有这样枚举:

enum EnumA
{
  stuffA = 0
};
enum enumAA
{
  stuffA = 1
};

什么时候你是指 stuffA 在这里会发生什么?我以为你会参考他们像 EnumA.stuffA EnumB.stuffA 在Java中,但不似乎是这种情况。

What happens here when you refer to stuffA? I thought you would refer to them like EnumA.stuffA and EnumB.stuffA as in java, but that doesn't seem to be the case.

感谢您的见解。

编辑 - 感谢迅速答复!

Edit-Thanks for the speedy replies!

推荐答案

枚举不引入新的作用域。

在你的榜样,第二个枚举不会编译由于 stuffA 名称冲突。

In your example, the second enum wouldn't compile due to the stuffA name clash.

要避免名称冲突,它是一种常见的做法,让一个枚举共同preFIX的元素。不同prefixes将用于不同枚举:

To avoid name clashes, it is a common practice to give the elements of an enum a common prefix. Different prefixes would be used for different enums:

enum EnumA
{
  EA_stuffA = 0
};
enum EnumAA
{
  EAA_stuffA = 1
};

这篇关于枚举范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆