使用枚举而没有变量名 [英] The use of enum without a variable name

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

问题描述

我明白第一个,但第二个?什么时候和为什么你会这样做?

I understand the first one but the second one? When and why would you do that?

enum cartoon { HOMER, MARGE, BART, LISA, MAGGIE };

enum { HOMER, MARGE, BART, LISA, MAGGIE };


推荐答案

,它给它一个范围,并帮助暴露类的功能,例如

you can define such enum in a class, which gives it a scope, and helps expose class's capabilities, e.g.

class Encryption {
public:
  enum { DEFAUTL_KEYLEN=16, SHORT_KEYLEN=8, LONG_KEYLEN=32 };
  // ...
};

byte key[Encryption::DEFAUTL_KEYLEN];

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

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