Okay, I’ve been inspired to do some head punching. Seems like overloading operator& leads to not a small amount of pain.
What legitimate cases exist for overloading it?
(Can’t say I’ve ever done that….)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I seem to remember something like a smart pointer class which overrode
operator&because it wanted to return the address of the contained pointer rather than the address of the smart pointer object. Can’t remember where I saw it or whether it seemed like a good idea at the time.Aha, remembered: Microsoft’s CComPtr.
Edit: To generalize, it might make sense under the following conditions:
Returning anything other than a legitimate pointer would violate the principle of least astonishment.