mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-03 10:33:25 +08:00
update
This commit is contained in:
43
codingStyleIdioms/2_enumclass/namespace.cpp
Normal file
43
codingStyleIdioms/2_enumclass/namespace.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by light on 19-12-9.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
// 在创建枚举时,将它们放在名称空间中,以便可以使用有意义的名称访问它们:
|
||||
namespace EntityType {
|
||||
enum Enum {
|
||||
Ground = 0,
|
||||
Human,
|
||||
Aerial,
|
||||
Total
|
||||
};
|
||||
}
|
||||
|
||||
void foo(EntityType::Enum entityType)
|
||||
{
|
||||
if (entityType == EntityType::Ground) {
|
||||
/*code*/
|
||||
}
|
||||
}
|
||||
|
||||
// enum class
|
||||
enum class EntityType1 {
|
||||
Ground = 0,
|
||||
Human,
|
||||
Aerial,
|
||||
Total
|
||||
};
|
||||
|
||||
void foo(EntityType1 entityType)
|
||||
{
|
||||
if (entityType == EntityType1::Ground) {
|
||||
/*code*/
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user