No, you've gone the wrong way in your last step.
*new int => *(new int)
*(new int) => *(pointer to an int)
Now what happens when you apply * the dereference operator to a
pointer? You get the object pointed to by that pointer, so
*(poiner to an int) => (the int)
So in the code
int& i = *new int;
i is a reference to the newly created int.
Gavin Deane
Here's how I like to think of it.
int &i = *new int;
First of all, that's the same as:
int &i = * (new int);
The thing on the left hand side of the assignment is of the type "int". The
thing on the left hand side of the assignment must an l-value of type "int".
Let's break it down into expressions. First let's look at the following
expression:
new int
The type of this expression is "int *", as "new" returns a pointer to the
object that's created. If you stick an asterisk behind an expression of type
"int*", you're left with an expression of type "int". Therefore, the
following expression is of the type "int":
*new int
Now we can bind a reference to it.
int &i = *new int;
delete &i;
-Tomás