相关疑难解决方法(0)

什么是聚合和POD以及它们如何/为何特殊?

常见问题解答涉及聚合和POD,并涵盖以下材料:

  • 什么是聚合
  • 什么是POD(普通旧数据)?
  • 它们有什么关系?
  • 它们如何以及为何特别?
  • C++ 11有什么变化?

c++ aggregate standard-layout c++11 c++17

525
推荐指数
6
解决办法
13万
查看次数

平凡与标准布局与POD

通俗地说,琐碎类型,标准布局类型和POD之间有什么区别?

具体来说,我想确定是否new Tnew T()任何模板参数不同T.哪种类型的性状is_trivial,is_standard_layout而且is_pod我应该选择?

(作为一个附带问题,可以在没有编译器魔法的情况下实现任何这些类型特征吗?)

c++ constructor initialization pod type-traits

69
推荐指数
2
解决办法
8729
查看次数

是否有编译时func /宏来确定C++ 0x结构是否为POD?

我想要一个C++ 0x static_assert来测试给定的结构类型是否是POD(以防止其他程序员无意中用新成员破坏它).即

struct A // is a POD type
{
   int x,y,z;
}

struct B // is not a POD type (has a nondefault ctor)
{
   int x,y,z; 
   B( int _x, int _y, int _z ) : x(_x), y(_y), z(_z) {}
}

void CompileTimeAsserts()
{
  static_assert( is_pod_type( A ) , "This assert should not fire." );
  static_assert( is_pod_type( B ) , "This assert will fire and scold whoever added a ctor to the POD type." ); …
Run Code Online (Sandbox Code Playgroud)

c++ static-assert type-traits c++11

22
推荐指数
1
解决办法
3265
查看次数

类外的默认构造函数/析构函数?

以下是否符合C++ 11标准(= default在类的定义之外)?

// In header file
class Test
{
    public:
        Test();
        ~Test();
};

// In cpp file
Test::Test() = default;
Test::~Test() = default;
Run Code Online (Sandbox Code Playgroud)

c++ constructor destructor default-constructor c++11

13
推荐指数
1
解决办法
7170
查看次数