Is there any other language having something similar to the way one can implement dereference as a method?

In Rust, we can simply implement the Deref trait on a type and have that type behave according to the deref method's definition, when being dereferenced.

I wonder, is there any other language having such a capability?

See here for more info on the Deref trait.

Looks like you can overload the dereference operator in CPP:

also, when using the method call syntax, C++ arrow (->) operator is automatically chased until a real pointer type is reached, (similar to but not the same as auto deref coercion in rust), which is the mechanism supporting C++ smart pointers.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.