The compiler message is one of those messages that don't make sense from the language point of view, but reveal the inner workings of the compiler, the sequence in which its inner logic works.
In your case you are using an rvalue (NULL
) to initialize a reference. When such initialization is allowed, the rvalue is converted to a temporary object, to which the reference will be bound. So, the compiler has realized it right away and informed you about the fact with a diagnostic message.
In reality though, the trick like that is only allowed for const
references, so your code is broken, since the reference is not const
in our case. Also, a struct
reference, as the one in your code, cannot be initialized with NULL
rvalue (which has integral type), so it is broken for that reason as well.
The compiler's message is rather misleading though. The text of the message seems to imply that it is illegal to initialize member references with temporary objects. In fact, this is legal in C++ (once the above problems are fixed), although it makes no sense. But, I guess, once ill-formed code is accompanied by at least some error message, it should be OK for everyone...