加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

这个结构POD在C 11?

发布时间:2020-12-16 05:35:51 所属栏目:百科 来源:网络整理
导读:这个结构是C11中的POD吗? struct B{ int a; B(int aa) : a(aa) {} B() = default;}; 请注意,这个问题对C 11是明确的.我知道这个类不是C98或C03中的POD. 有关C 11中POD的说明,请参见trivial vs. standard layout vs. POD (灵感来自这个问题:Is there a comp
这个结构是C11中的POD吗?
struct B
{
  int a;
  B(int aa) : a(aa) {}
  B() = default;
};

请注意,这个问题对C 11是明确的.我知道这个类不是C98或C03中的POD.

有关C 11中POD的说明,请参见trivial vs. standard layout vs. POD

(灵感来自这个问题:Is there a compile-time func/macro to determine if a C++0x struct is POD?)

解决方法

是的,这是根据 new rules的POD.

如果您查阅新标准的§8.4.2/ 4段,您可以看到,如果构造函数在第一个声明中是默认的,则不是用户提供的:

Explicitly-defaulted functions and implicitly-declared functions are
collectively called defaulted functions,and the implementation shall
provide implicit definitions for them (§12.1 §12.4,§12.8),which might
mean defining them as deleted. A special member function is
user-provided if it is user-declared and not explicitly defaulted or
deleted on its first declaration. (…)

您可以使用std :: is_pod类型trait为您提供带有static_assert的编译器test this.

static_assert(std::is_pod<B>::value,"B should be a POD");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读