使用const元素的struct不是一件容易的事吗?

时间:2014-07-13 18:34:13

标签: c++ c++11

关于以下代码,我理解结构B即使在删除注释标记后也没有默认构造函数。因此,第一个静态断言失败。我也明白第二个静态断言不会失败"按照定义"。

struct B
{
    const int value;
    // B() = default;
};

int main()
{
    static_assert( std::is_trivially_constructible<B>::value, "B should be trivially constructible" );
    static_assert( std::is_trivially_constructible<const int>::value, "const int should be trivially constructible" );
}

但是,我认为结构和封闭的常数整数是&#34;基本相同&#34;当涉及到构建它们所需的步骤时。我得出的结论是&#39; std :: is_trivially_constructible&#39;不反映&#34;创建对象所采取的步骤&#34;。

你是否有能够取代我的精神图片(其中&#39; is_trivially_constructible&#39;与如何创建对象有关)?

0 个答案:

没有答案