At run time, C ++ makes no distinction between class and structure, and a union can only be distinguished from the fact that all its data members share the address space.
Thus, the only way to achieve this is to include metadata in your class / struct / union definitions that support the differences that are important to you. For instance:
typedef enum { class_ct, struct_ct, union_ct } c_type; class foo { public: c_type whattype() { return class_ct; } }; struct bar { public: c_type whattype() { return struct_ct; } }; union baz { public: c_type whattype() { return union_ct; } };
// B
source share