Why is overloading operator&() prohibited for classes stored in STL containers?

Posted by sharptooth on Stack Overflow See other posts from Stack Overflow or by sharptooth
Published on 2010-04-27T08:46:51Z Indexed on 2010/04/27 8:53 UTC
Read the original article Hit count: 240

Suddenly in this article ("problem 2") I see a statement that C++ Standard prohibits using STL containers for storing elemants of class if that class has an overloaded operator&().

Having overloaded operator&() can indeed be problematic, but looks like a default "address-of" operator can be used easily through a set of dirty-looking casts that are used in boost::addressof() and are believed to be portable and standard-compilant.

Why is having an overloaded operator&() prohibited for classes stored in STL containers while the boost::addressof() workaround exists?

© Stack Overflow or respective owner

Related posts about c++

Related posts about operator-overloading