c++ 匿名枚举
来源:互联网 发布:北京奥运会门票知乎 编辑:程序博客网 时间:2024/05/29 14:36
匿名枚举
刚看到时候有些奇怪,经过考察,他的功能等价于静态常成员变量,
写了一个更一般的例子,果然。
如果有不对请指出,共同学习进步哦!thx
enum { value = 0 , value2 = 1};
enum { value3 = 2};
enum { value3 = 2};
刚看到时候有些奇怪,经过考察,他的功能等价于静态常成员变量,
struct IsCustomUnsignedInt
{
enum { value = 0 , value2 = 1};
enum { value3 = 2};
static const int value4 = 3;
static int value5;
};
int IsCustomUnsignedInt::value5 = 4;
void main()
{
int result = IsCustomUnsignedInt::value;
int result2 = IsCustomUnsignedInt::value2;
IsCustomUnsignedInt::value3 = 3; //error C2440: '=' : cannot convert from 'int' to ''
//IsCustomUnsignedInt::value4 = 4; //error C3892: 'value4' : you cannot assign to a variable that is const
IsCustomUnsignedInt::value5 = 5;
}
{
enum { value = 0 , value2 = 1};
enum { value3 = 2};
static const int value4 = 3;
static int value5;
};
int IsCustomUnsignedInt::value5 = 4;
void main()
{
int result = IsCustomUnsignedInt::value;
int result2 = IsCustomUnsignedInt::value2;
IsCustomUnsignedInt::value3 = 3; //error C2440: '=' : cannot convert from 'int' to ''
//IsCustomUnsignedInt::value4 = 4; //error C3892: 'value4' : you cannot assign to a variable that is const
IsCustomUnsignedInt::value5 = 5;
}
写了一个更一般的例子,果然。
enum Type{First,Second,Third};
struct TestEnum {
enum Type2{One,Two,Three};
void Test()
{
int i = One;
}
};
void main()
{
int i = First;
TestEnum test;
test.Test();
//int x = One; //error
int j = TestEnum::One;
}
struct TestEnum {
enum Type2{One,Two,Three};
void Test()
{
int i = One;
}
};
void main()
{
int i = First;
TestEnum test;
test.Test();
//int x = One; //error
int j = TestEnum::One;
}
如果有不对请指出,共同学习进步哦!thx
- 匿名枚举
- 匿名枚举
- 匿名枚举
- c++ 匿名枚举
- C++ 匿名枚举
- C-枚举
- C-枚举
- C 枚举
- C-枚举
- c#---枚举
- 枚举【C#】
- 【c#】枚举
- 【C#】枚举
- 匿名内部类抽象实现枚举
- 枚举、匿名内部类学习笔记
- 不允许SAM账户的匿名枚举
- C.匿名管道
- C#:匿名方法
- 第四周C++上机报告(时间类)
- win7登陆界面隐藏Guest用户名
- git的优点
- N皇后问题
- android3D 正方体,触摸旋转
- c++ 匿名枚举
- Resource is out of sync with the file system解决办法
- Apache Log4j配置说明
- display属性值
- struts2+spring+hibernate3.3增删改查的实例图文详解
- myeclipse 一些初始化设置
- 向上取整
- CADENCE公司简介
- android程序退出方案