On pg. 149 of Jumping into C++, the author states:
In general, you should not store memory that you just allocated in a reference:
int &val = *(new int);
The reason is that a reference does not provide immediate access to the raw memory address. You can get it using & , but generally references should provide an additional name for a variable, not storage for dynamically allocated memory.
What does this mean on the right-hand side of the reference intialization?
I understand the notation of declaring (and immediately initializing) a reference as follows:
int x = 1;
int &ref = x;
But I don't understand what *(new int)
refers to in the passage. And whatever it means, is it illegal to do this, or just a bad practice?