//在用枚举的时候总觉得很迷惑
//为什么枚举里的值在定义的外面就可以直接使用了呢?
//例如:enum computer{lenovo,asus};
//compzuoyouter c = asus;
//ASUS直接就可以使用而不需要c=computer::asus;
//原来enum的{}没有作用域的作用
//如果你在相同的作用域中定义:
/*
enum computer{lenovo,asus};
enum computer2{lenovo,asus};
会出现重复定义的错误
*/
#include <iostream>
using namespace std;
class Lenovo{
public:
Lenovo(){ cout << "a Lenovo computer created" << endl; }
~Lenovo(){ cout << "a Lenovo computer destoryed" << endl; }
enum value{low=1000,high=5000};
void show(){ cout << "Leenovo" << endl; }
};
enum value2{ low = 100, high = 5000 };
//enum value3{ low = 1000, high = 5000 };
int main(){
value2 d = low;
Lenovo create;;
cout << create.low << endl;
cout << Lenovo::low << endl;
cout << d << endl;
return 0;
}
enum
最新推荐文章于 2022-05-09 15:48:08 发布