I saw some code as follows:
class A
{
private:
union {
B *rep;
A *next;
}; // no variables of this anonymous defined!
void func()
{
A *p = new A;
p->next = NULL; // why p has a member variable of 'next'?
}
};
I have compiled the above code with VS2010 without any error. Here is the question,
why p has member variable 'next'?
union {
B *rep;
A *next;
};
As far as I know, this is an anonymous union without even defining a variable. How can we access the member variables inside this union like that?