【发布时间】:2012-09-21 12:52:58
【问题描述】:
结构的属性是在 C++ 中继承的
例如:
struct A {
int a;
int b;
}__attribute__((__packed__));
struct B : A {
list<int> l;
};
struct B(struct A)的继承部分会继承packed属性吗?
如果没有收到编译器警告,我无法将 attribute((packed)) 添加到结构 B:
ignoring packed attribute because of unpacked non-POD field
所以我知道整个 struct B 不会被打包,这在我的用例中很好,但我需要将 struct A 的字段打包到 struct B 中。
【问题讨论】:
-
你确定A中需要这个属性,还是A只是一个例子?
标签: c++