I can't give any "proof," but I can tell you that a reference to a pointer is perfectly fine and legal. It's useful for the same reason any reference parameter is useful: the function can modify the original parameter, and the caller doesn't need to make
his code look messy by passing a pointer to a pointer.
My guess is that [tt]f(&m)[/tt] doesn't work just because there's no variable to take the reference of. The return value from [tt]new[/tt], on the other hand, is getting treated as a temporary anonymous variable that only exists as long as there's a reference to it.
Does it work better if you try this?
Code:
MyClass m;
MyClass *mp = &m;
f(mp);
Actually, for me, neither #1 nor #2 compile, and my above suggestion does. I'm using GCC 3.2.
Therefore, it may just be a bug in your compiler. Maybe it shouldn't be compiling either of them. That is, perhaps the result of a function or operator call ([tt]new[/tt]) shouldn't be a temporary variable, and since there aren't any variables involved to take the reference of, neither example is legal.
You'd have to get someone to comb through the C++ Standard to figure out what behavior is correct, and I'm not volunteering.