[C++-sig] Wrapping a class with private operator&()

David Abrahams dave at boost-consulting.com
Sat Oct 8 15:15:31 CEST 2005


Matthias Baas <baas at ira.uka.de> writes:

> Hi,
>
> I'm having problems wrapping a C++ class that has a private reference 
> operator (operator&()). 

Well, first of all, don't do that.  A class whose address-of operator
doesn't do the normal thing is going to **break** just about every
generic library you try to use it with in exactly this way.  It's
generally agreed that overloading operator& is pure evil except in
very special circumstances.  It doesn't do anything, really, to
protect you: there's a function template in Boost called addressof
that can produce a pointer to the object anyway.

> Here is a minimal example that shows the problem:

In the enclosed patch, I replaced enough uses of "&" with addressof to
make your example compile, but I'm almost certain there will be other
such instances.  If you try it and it works for you, I'll check it in.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: value_holder.patch
Type: text/x-patch
Size: 1485 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20051008/722b332f/attachment.bin>
-------------- next part --------------


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


More information about the Cplusplus-sig mailing list