Boost logo

Boost Users :

Subject: Re: [Boost-users] [shared_ptr] Error in Constructor
From: Peter Dimov (pdimov_at_[hidden])
Date: 2010-05-22 14:12:40


David Greene wrote:

>> testbed.cpp:33: error: operands to ?: have different types
>> `boost::shared_ptr<Base>' and `boost::shared_ptr<A>'
>
> Well, yes. Without BOOST_SP_NO_SP_CONVERTIBLE, the test does not
> generate that error. If the code used bare pointers the error would
> also not occur, so it's surprising to see it just by using a smart
> pointer.

The enable_if test disables the shared_ptr<Base> to shared_ptr<A>
conversion, so there is no longer any ambiguity.

> That's really bad. It effectively means one can't easily tell when one
> might
> need the full definition of a type. I ran into this because I wanted to
> decouple some code defining the body of one function that takes one
> type from the body of another that takes a different type. In terms of
> the example, I didn't want changes to A to cause recompilation of
> functions that take a Wrapper<B>.

I see how that might be a problem, but I don't see a solution. Either way,
someone loses. I'd probably remove the typedef typename Tag::type type in
this case, as it's the only thing requiring the definition of A.


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