A Plain Old Data (POD) structure is an aggregate class that contains only PODs as members. It doesn’t have any user-defined constructors or destructors. There are also no non-static members of the pointer-to-member type in it.
A POD structure is a struct or class which only has member variables. It doesn’t contain virtual functions, methods, constructors, destructors, and so on.
A POD is basically a type (including the classes) which ensures that there is no hidden thing in the compiler such as: hidden pointers to the vtable, constructors, destructors, etc. A type is a POD if the only things are built-in types and the combinations of the types.
Let’s discuss a basic example to understand the concept of POD.
#include<iostream>using namespace std;struct Employee{string name;int age;};int main(){struct Employee e;e.age = 21;e.name = "Behzad";return 0;}
Lines 3–7: We make a struct that has two member variables, namely name
and age
.
Line 10: We make the object of the struct.
Lines 11–12: We assign values to the variables of the struct.
Since this struct doesn’t have any constructors or destructors, it’s an example of a POD.