The fact that a pointer can't be passed by reference
they can. Its ugly..
1 2 3 4 5
|
void allocate(char *& cp)
{
cp = new char[1000];
} //if not passed by reference, this would leak the memory and the passed in
//pointer would still be junk!. Passed by reference, the value created by the 'new' is kept.
|
this is the sort of thing we try to avoid, though.
---------------
Bc when you have 2 things interacting the pointer represents a unique id to that reference.
I have no idea what you are trying to say here.
...
there would be no way for one to reference the other.
at the assembly / compiler level, this is not true. Its all effectively global down there. This is a c++ problem, and the reference is a token you can use to access the thing, yes. But it does not HAVE to become an entity in the binary code. It can be directly loaded into a register by value without 'existing' on the stack or in ram (its in the code segment, though, as a hard value).
A pointer isn't a type of reference. Pointers are integer values that hold a number that is akin to an array index into ram:
if your data is in ram[100042];
then a pointer would be
x = 100042;
ram[x] is akin to *x and c++ supports that syntax (array notation)
but the key here is that x is an actual variable on the stack or heap somewhere. You can change its value.
a reference is something else.
say variable z is at location 4400.
then thing &y = z
y and z are the same thing. there is no pointer.
y and z both read or write location 4400, but 4400 isnt stored anywhere you can touch. Its a token in the assembly language, and y and z both get replaced with that token. Unless you did something to prevent this. You can't change the 4400, you can't even change what y refers to later if you changed your mind, it has to be redefined (eg a loop can contain thing &tmp = container[i] and each iteration tmp is rebuilt)