私は現代のC++デザインから取られた次のコードを持っています。それを使用している間、compiationエラーが発生します。opearandのサイズが無効だと思います。誰もが問題が何であるかを指摘できますか?ありがとう!
template<bool>
struct CompileTimeChecker {
CompileTimeChecker(...);
};
template<>
struct CompileTimeChecker<false> {
};
#define STATIC_CHECK(expr, msg) \
{\
class ERROR_##msg {}; \
(void)sizeof(CompileTimeChecker<(expr) != 0>((ERROR_##msg())));\
}
template <class To, class From>
To safe_reinterpret_cast(From from) {
STATIC_CHECK(sizeof(From) <= sizeof(To), Destination_Type_Too_Narrow);
return reinterpret_cast<To>(from);
}
int main(void)
{
int a[20];
void* somePointer = a;
char c = safe_reinterpret_cast<int>(somePointer);
}
エラー:
d:\technical \ c ++ study \ readparsing \ readparsing \ addressconv.cpp(29):エラーC2066:関数型へのキャストが不正です1> d:\technical \ c ++ study \ readparsing \ readparsing \ addressconv.cpp( 37):関数テンプレートのインスタンス化への参照を参照'to safe_reinterpret_cast(From)'コンパイル中1> with 1> [1> To = int、1> From = void * 1>] 1> d:\technical \ c ++ study \ readparsing \ readparsing \ addressconv.cpp(29):エラーC2070:'CompileTimeChecker <__formal>(safe_reinterpret_cast :: ERROR_Destination_Type_Too_Narrow(__cdecl *)(void))':不正なsizeofオペランド1> with 1> [1> __formal = true 1 >]