I was just wondering why anonymous unions cannot contain member functions. I believe that regular, named unions can have member functions, and what makes anonymous ones different?
Anonymous unions can hold regular variables that are in the scope right above the union. Why can't functions be the same?
Member functions have an implicit pointer parameter to the type their associated with. Since anonymous unions, structures, and classes are not types, what type would the member function use as its parameter? For example:
1 2 3 4 5 6 7 8 9
struct X
{
void f(X *x_, int a_); // "x_" is an implicit parameter.
};
union // Not a type.
{
void f(???, int a_); // No type to refer to. Error.
};