sizeof in preprocessor command doesn't compile with error C1017

后端 未结 4 644
迷失自我
迷失自我 2021-01-29 16:46

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:

4条回答
  •  春和景丽
    2021-01-29 17:18

    As @some-programmer-dude mentioned in the comment, sizeof is not part of the preprocessor.

    you should use if constexpr if you want it to work in compile time.

    if you don't care if it happens in compile time or run-time just use a regular if statment

    keep in mind that if constexpr is a new feature in C++17!

提交回复
热议问题