Boost logo

Boost Users :

From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2007-01-04 17:00:56


On 1/4/07, Peter Dimov <pdimov_at_[hidden]> wrote:
> The problem with operator& for a smart pointer is that the smart pointer can
> already have a value. When you hand the address of its raw pointer to
> QueryInterface, it will overwrite its old value without calling Release() on
> it. You can guard against that by always zeroing the pointer in operator&,
> but this leads to a different problem; the expression &x will set x to zero,
> something that isn't expected or intuitive. Operator& is evil. :-)

One of (or both?) of Microsoft's smart pointers (i.e. IVideoPtr,
CComPtr<IVideo>) assert if operator& is called and the pointer is not
zero for that reason...or maybe it throws a COM exception, I can't
remember.

(Not disagreeing with anything that's been said, simply offering
information the OP might find useful if he wants to make his operator
behave like MS's).

--Michael Fawcett


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net