【发布时间】:2014-11-12 06:59:07
【问题描述】:
为什么 static_assert 需要在类定义之外?
失败代码
#include <type_traits>
class A
{
public:
A(A&&) noexcept {}
static_assert(std::is_nothrow_move_constructible<A>::value, "ERROR");
};
int main()
{
}
工作代码
#include <type_traits>
class A
{
public:
A(A&&) noexcept {}
};
static_assert(std::is_nothrow_move_constructible<A>::value, "ERROR");
int main()
{
}
什么时候适合在类或结构的定义中使用 static_asserts?
【问题讨论】:
-
第一个有什么问题?有错误信息吗?
-
我已编辑问题标题以匹配问题内容。
-
@0x499602D2 使用 g++ --std=c++11 {code} is_nothrow_move_constructible.cpp:8:1: error: static assertion failed: ERROR static_assert(std: :is_nothrow_move_constructible::value, "ERROR"); {代码}
标签: c++ c++11 typetraits static-assert