4

In c++, why we can overload operator -> and can't overload operator .?
Similarly, why we can overload operator ->* and can't overload operator .*?
I will be appreciated if you can help me!

Jarod42
  • 203,559
  • 14
  • 181
  • 302

1 Answers1

4

Stroustrup actually has this as an FAQ question on his website. To quote his answer:

Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by .

This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best

(Note that Stroustup himself has since proposed allowing overloading of operator., as have others, so we may see it in a future version of the language.)

Community
  • 1
  • 1
Tristan Brindle
  • 16,281
  • 4
  • 39
  • 82