具有所有私人成员的班级可以成为POD班级吗? [英] Can a class with all private members be a POD class?
问题描述
我之前听说过POD类型不能拥有私有数据-但根据C ++ 0x草案,我的要求是宽松的(强调我的意思):
I've heard before that POD types cannot have private data -- but according to the C++0x draft I have the requirement is looser (emphasis mine):
对所有非静态数据成员具有相同的访问控制(第11条)
这似乎表明只要所有数据都是私有的,私有数据就可以.我没有C ++ 03的副本,但是要检查...
which seems to suggest that private data is okay so long as it's all private. I don't have a copy of C++03 though to check...
然后, WindowsApi :: Uuid
是POD类吗?
namespace WindowsApi
{
class Uuid
{
union
{
::UUID asUuid; //Win32's UUID struct
unsigned __int64 asInt64s[2];
unsigned __int32 asInt32s[4];
};
public:
Uuid() {}
Uuid(::UUID sourceStructure) : asUuid(sourceStructure) {}
operator ::UUID() { return asUuid; }
};
}
推荐答案
C ++ 03仍然不允许POD类中的非静态私有数据或受保护的数据.在 aggregate
C++03 still does not allow non-static private or protected data in POD classes. This requirement is specified in the definition of aggregate
集合是没有用户声明的构造函数(12.1),没有私有或受保护的非静态数据成员(第11条),没有基类(第10条),并且没有虚函数(10.3).
An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).
和POD类必须首先是集合.
and POD class must be an aggregate first.
这篇关于具有所有私人成员的班级可以成为POD班级吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!