So I’ve been thinking (while reading this Java pdf)…
I know this may seem silly but why can’t I do this in c++.
float &f = new float;
Isn’t this saying the reference of f is the address of new float?
In Java, I see something like this
String s = new String("something")
String s is called a string reference.
Does the word ‘reference’ in Java have the same meaning as in C++?
Java references are much closer to C++ pointers rather than C++ references. In Java, you can do the following with a reference:
In C++, pointers have these same properties. As a result, the code you’re looking for in C++ is something like
Which is perfectly legal. For a better comparison, this Java code:
would map to this C++ code:
Hope this helps!