Please help me understand this syntax (implementing static assert in C++)

后端 未结 4 1413
粉色の甜心
粉色の甜心 2021-01-02 20:05

This syntax was used as a part of an answer to this question:

template 
struct static_assert;

template <>
struct static_assert         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 20:52

    Well, I guess it is about template specialization. STATIC_ASSERT(true) will compile successfully, because there is a definition (not just a declaration) of "static_assert< true >".

    STATIC_ASSERT(false) will be rejected by the compiler, because there is only a declaration for "static_assert< false >" and no definition.

    Update: for visual studio, STATIC_ASSERT(true) is ok, but STATIC_ASSERT(false) triggers the error: "error C2514: 'static_assert<__formal>' : class has no constructors [ with __formal = false ]"

提交回复
热议问题