Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 打包包含打包的非POD元素的std::数组的类_C++ - Fatal编程技术网

C++ 打包包含打包的非POD元素的std::数组的类

C++ 打包包含打包的非POD元素的std::数组的类,c++,C++,我有一个带有显式构造函数的类来支持更强的类型 我希望另一个类能够包含这些对象的std::array,并且也可以打包 class __attribute__((packed)) NonPOD { private: int m_i; public: explicit NonPOD(int i) : m_i(i) {} }; class __attribute__((packed)) PackedDownstream { private: NonPOD a[2];

我有一个带有显式构造函数的类来支持更强的类型

我希望另一个类能够包含这些对象的
std::array
,并且也可以打包

class __attribute__((packed)) NonPOD {
  private:
    int m_i;
  public:
    explicit NonPOD(int i) : m_i(i) {}
};

class __attribute__((packed)) PackedDownstream {
  private:
    NonPOD a[2];
};

class __attribute__((packed)) PackedDownstreamWithStdArray {
  private:
    std::array<NonPOD, 2> a;
};

class __attribute__((packed)) POD {
  public:
    int m_i;
}

class __attribute__((packed)) PackedPOD {
  private:
    std::array<POD, 2> a;
}

有没有办法(a)强制显式构造函数和(b)在压缩的
std::array
中使用类?

请注意
std::array
本身可能有填充,您对此无能为力。请注意
std::array
本身可能有填充,您对此无能为力。
warning: ignoring packed attribute because of unpacked non-POD field ‘std::array<NonPod, 2> PackedDownstreamWithStdArray::a’