A POD type in C++ is an aggregate class that contains only POD types as members, has no user-defined destructor, no user-defined copy assignment operator, and no nonstatic members of pointer-to-member type.
http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7 seems to indicate that it can have *no* constructors.
It doesn't matter what parashift states. They are wrong. What matters, is the information contained in the ISO std, yes?
From the ISO std:
1 2
An object of POD4) type (3.9) shall occupy
contiguous bytes of storage.
Yes it matters and aren't you the one who brought it up in the first place? If you scan the std you'll see references to POD all over. I did a quick scan and found about 50 references to rules relating specifically to POD types.
From the ISO std:
"A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct,
non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator
and no user-defined destructor."
kempofighter, I think the confusion comes from the definition of "aggregate type" (used by helios, above).
From ISO/IEC 14882:1998(E), section 8.5.1, paragraph 1 (emphasis mine):
An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or pro-
tected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).
Definition of what a POD is seems rather arbitrary anyway. Does it really matter?
In this case, almost certainly not. But it is important when interfacing with C APIs. It is very easy to accidentally change a POD struct into a non-POD struct and screw up compatibility. For instance, you can memcpy a POD struct, but cannot do that with non-POD types. I know this because I recently screwed up some code this way. Learning from your own mistakes is a bitch. :-)
For instance, you can memcpy a POD struct, but cannot do that with non-POD types.
Wait, are you saying no struct with a constructor can be memcpy()ed? How does having a function is in a struct's namespace affect the adjacency of the struct's members?
Wait, are you saying no struct with a constructor can be memcpy()ed? How does having a function is in a struct's namespace affect the adjacency of the struct's members?
It is undefined behavior to memcpy non-POD types. Or, put another way, the result of memcpy in C++ is only defined for POD types.
Well I hate being wrong but I guess I am. I see what the FAQ writer is saying. The reading of the std is pretty gnarly in that case since you have to read multiple sections just to understand what a POD type is.
Yes. Structs have a separate namespace in C. It works in C++ too, but you must, as in C, use the 'struct' keyword to indicate that you want the struct tag namespace over the normal identifier namespace.