Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
_pmf_
on May 16, 2017
|
parent
|
context
|
favorite
| on:
String.intern()
> How would you expect a programmer to ask "do these two pointers hold the same address?" .holdsSameAddressAs()?
In C++, yes, you do
(&a == &b)
and the plain == is used for the common case of actually doing what you mean (what in Java would be .equals()).
sherincall
on May 17, 2017
[–]
Actually, that's not always correct in C++ (it is in C). It is possible that either type has the operator& overloaded, so instead the proper way to do it is:
(std::addressof(a) == std::addressof(b))
http://en.cppreference.com/w/cpp/memory/addressof
_pmf_
on May 17, 2017
|
parent
[–]
Thanks (I didn't even know this operator was overloadable)!
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
In C++, yes, you do
and the plain == is used for the common case of actually doing what you mean (what in Java would be .equals()).