The exact posted code has has defined behavior under c++11, since demo is a standard-layout class and info (the data member) is accessed as a compatible type, but it is bad style.
Standard-layout class must:
- Have the same access control for all data members
- Have no virtual functions
- Only inherit from standard-layout classes
- At most one class in its class hierarchy has data members
- Has no data members with the same type as any in the class hierarchy
This text is simplified from 9.7 of the draft standard. In my terminology, class hierarchy includes the class itself, and data members only covers non-static data members.
Accessing the data member with an incompatible type would cause undefined behavior, as always. For instance short is undefined, but char and int is defined.
In short, such access is defined if the class is standard-layout . So be VERY careful. You can check if a type is standard-layout with std::is_standard_layout