In c++, the * operator can be overloaded, such as with an iterator, but the arrow (->) (.*) operator does not work with classes that overload the * operator. I imagine that the preprocessor could easily replace all instances of -> with (*left).right, and that would make iterators nicer to implement. is there a practical reason for -> to be different, or is that just a peculiarity of the language/designers?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
The rule that
It would make the language more bothersome if anything that overloads unary
Also note that such an overload would have some rather interesting properties, like automatically chaining
"The C++ Programming Language" describes the fact that these operators are different so that they can be, but also says:
So it seems that the language designers provided separate overload points because you might want to overload them differently, rather than assuming that you always want them to be the same.
As a general rule, C++ is designed to favor flexibility, so overloads of
That said, iterators do support either usage. On ancient implementations, you might find a library that requires