0
컴파일러가 여기에서 불평하는 이유는 무엇입니까? 나중에 코드에서초기화에서 익명 열거 형을 변환 할 수 없습니다.
enum jit_ptx_type {f32=0,f64=1,u16=2,u32=3,u64=4,s16=5,s32=6,s64=7,u8=8,b16=9,b32=10,b64=11,pred=12 };
//
// MATCHING C TYPES TO PTX TYPES
//
template<class T> struct jit_type {};
template<> struct jit_type<float> { enum { value = jit_ptx_type::f32 }; };
template<> struct jit_type<double> { enum { value = jit_ptx_type::f64 }; };
template<> struct jit_type<int> { enum { value = jit_ptx_type::s32 }; };
template<> struct jit_type<bool> { enum { value = jit_ptx_type::pred }; };
:
some_func(float val) {
jit_ptx_type type = jit_type<float>::value; // compiler complains here
}
컴파일러 메시지 :
error: cannot convert ‘jit_type<float>::<anonymous enum>’ to ‘jit_ptx_type’ in assignment
이 이상하다! 이 줄을 별도의 작은 예제 파일에 넣으면 작동합니다.
범위가 지정되지 않은 enum은 자격을 사용하지 않습니다. 내가 사용하는 줄'static constexpr int 값 = ...;',. – chris
당신은 정교 할 수 있습니까? – ritter
''jit_ptx_type :: f32' 대신'f32'가 필요합니다. 대신'enum class'를 사용하십시오. 비록 그것이 잘못된 문법이지만, 언뜻보기에는 오류와 관련이없는 것처럼 보입니다. – chris