enum sports{basketball,football,hockey,baseball,soccer,volleyball};
sports popularsport;
popularsport=football;
popularsport=static_cast<sports>(popularsports+(-)1);
枚举型可以有上面的用法,再结合其关系运算的可用性.则
for(mysport=basketball;mysport<=soccer;mysport=static_cast<sports>(mysport+1))
^^^^^^^^^^^^^^
但是同时上面的方法也可以完全转化成整数的运算,通过定义整数来进行相应的操作,在强制转换成sports类型!
sports popularsport;
popularsport=football;
popularsport=static_cast<sports>(popularsports+(-)1);
枚举型可以有上面的用法,再结合其关系运算的可用性.则
for(mysport=basketball;mysport<=soccer;mysport=static_cast<sports>(mysport+1))
^^^^^^^^^^^^^^
但是同时上面的方法也可以完全转化成整数的运算,通过定义整数来进行相应的操作,在强制转换成sports类型!
![](https://i-blog.csdnimg.cn/blog_migrate/7a9f8c2f833206445a63e9b8dc5b1286.gif)