Is there a way to get the number of members of a union in C++? For example:
union U
{
int a;
double b;
char c;
};
int main()
{
std::cout << std::union_members_count<U>::value << std::endl; // prints 3
}
Of course, std::union_members_count<>
is fictional.
If there is a way, how do I implement/use it?
No, this is not possible in C++.
C++ does not have reflection, a feature for code that describes itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With