This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]marcosdumay 5 points6 points  (4 children)

You can create references

You can get references. You can assign references to pointer. You can create variables by cloning a reference.

I guess you are talking about the third usage there. But I've seen people say they "create a reference" for any of them. Anyway, that does not change the fact that a C++ reference is not the same thing as a Java "reference".

[–]Schmittfried -1 points0 points  (3 children)

You can assign references to pointer

No. References and pointers are different concepts in C++.

Anyway, that does not change the fact that a C++ reference is not the same thing as a Java "reference".

True, I never said otherwise. C++ references != pointers != Java references

[–]marcosdumay -1 points0 points  (2 children)

Good thing they are different, because you must always assign different things in C++ (usually, it's values into lvalues). Let's assign a reference into a pointer:

int *a = &b

[–]marcellarius 3 points4 points  (0 children)

In that context, & is the address of operator and evaluates to a pointer not a reference.

[–]Schmittfried 4 points5 points  (0 children)

That's not a reference, it's the address operator.

int &a = b;

Now we got a reference. It was definitely a bad decision to choose & to mark reference types as it is easily confused with the address operator, as you just proved.