enum StudentType
{
A, // 0
B, // 1
C, // 2
Count // 3
}
타입이라기 보다는 실제로는 정수이다.
서로 다른 enum이라도 순서(=숫자)만 같아도 비교가 가능하다.
Type 체크를 안하기 때문 잘못된 비교 가능.
enum class StudentType
{
A,
B,
C,
Count
}
서로 다른 enum class끼리는 비교할 수 없다.
독자적 타입으로 인정되어 자료형 검사.
enum class StudentType : uint8_t
{
A,
B,
C,
Count
}
타입 고정 가능
for (int i = static_cast<int>(StudentType::A); i < static_cast<int>(StudentType::Count))
{
}
단순 int가 아니기 때문에 명시적 캐스팅을 해주어야 하는 불편함은 있다.