sizeof in preprocessor command doesn't compile with error C1017
问题 I want to use preprocessor command to control code executive path. Because in this way can save runtime time. #if (sizeof(T)==1 doesn't comple with error: C1017 template<typename T> class String { public: static void showSize() { #if (sizeof(T)==1) cout << "char\n"; #else cout << "wchar_t\n"; #endif } }; inline void test() { String<char>::showSize(); String<wchar_t>::showSize(); } 回答1: The preprocessor runs before the C++ compiler. It knows nothing of C++ types; only preprocessor tokens.