What are POD types in C++?

I've come across this term POD-type a few times.
What does it mean?

1162
2022-07-25 20:39:33
Source Share
Answers: 3

In brief, it is all constructed - in information types (as an example int, char, float, long, unsigned char, double, etc) and also all gathering of POD information. Yes, it is a recursive definition. ;)

To be extra clear, a POD is what we call "a struct": a device or a team of devices that simply store information.

33
2022-07-25 21:38:49
Source

With C+npls, Plain Old Data does not simply suggest that points like int, char, etc are the only types made use of. Level Old Data actually suggests in technique that you can take a struct memcpy it from one area in memory to an additional and also points will certainly function specifically like you would certainly anticipate (i.e. not explode). This breaks if your class, or any kind of class your class has, has as a participant that is a reminder or a reference or a class that has a digital function. Basically, if reminders need to be entailed someplace, its not Plain Old Data.

2
2022-07-25 20:50:31
Source

Very informally:

A POD is a type (including classes) where the C++ compiler guarantees that there will be no "magic" going on in the structure: for example hidden pointers to vtables, offsets that get applied to the address when it is cast to other types (at least if the target's POD too), constructors, or destructors. Roughly speaking, a type is a POD when the only things in it are built-in types and combinations of them. The result is something that "acts like" a C type.

Less informally:

  • int, char, wchar_t, bool, float, double are PODs, as are long/short and signed/unsigned versions of them.
  • pointers (including pointer-to-function and pointer-to-member) are PODs,
  • enums are PODs
  • a const or volatile POD is a POD.
  • a class, struct or union of PODs is a POD provided that all non-static data members are public, and it has no base class and no constructors, destructors, or virtual methods. Static members don't stop something being a POD under this rule. This rule has changed in C++11 and certain private members are allowed:
  • Wikipedia is wrong to say that a POD cannot have members of type pointer-to-member. Or rather, it's correct for the C++98 wording, but TC1 made explicit that pointers-to-member are POD.

Formally (C++03 Standard):

3.9(10): "Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to member types (3.9.2) and cv-qualified versions of these types (3.9.3) are collectively caller scalar types. Scalar types, POD-struct types, POD-union types (clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called POD types"

9(4): "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-define copy operator and no user-defined destructor. Similarly a POD-union is an aggregate union 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-define copy operator and no user-defined destructor.

8.5.1(1): "An aggregate is an array or 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)."

406
2022-07-25 20:47:39
Source