4 ms·
You are right that (2) needs to be dereferenced first, however, in go a pointer is autmatically dereferenced when accessing its properties or "methods". What I
by eraxley 7y ago
You are right that (2) needs to be dereferenced first, however, in go a pointer is autmatically dereferenced when accessing its properties or "methods". What I mean by this is that if you want to access a property on thing, it would look the same.
In C++ it would look like this:
(1) x = thing.Property;
(2) x = thing->Property; (or (*thing).Property)
but in go, both would look the same, like this:
(1) x = thing.Property
(2) x = thing.Property
So there is a difference syntactically, and the compiler will handle them differently, but whether the difference is semantically relevant is debatable.
- derangedHorse 7y agoThat's one of the things that I hate about Go. That and how they force me to write an 'else' on the same line as the closing brace of the 'if'.
- saagarjha 7y agoRust does this too, I think.
- steveklabnik 7y ago(Yes, it does.)