Date: 2001-10-17 14:39:01
--- In boost_at_y..., Sebastien Marc <sebmarc_at_y...> wrote:
> Yes steve, i understood that.
> What is not clear to me is that an exception is
> thrown. I would have expected the convertion, the
> actual cast from any, containing 5, to const char *)
> to work.
> To me, the resulting string s should contain "5" but
> instead the exception is thown.
The boost::any class does not allow you to coerce the type stored
into another type via any_cast<>. That's pretty appearant in the
documentation, and I didn't see any place in the article that seemed
to suggest otherwise. The sole purpose of any_cast<> is to cast a
boost::any into the type of object that is stored within the
boost::any object. If you store a const char* you can only
any_cast<> to a const char*. Attempts to do otherwise result in
either an exception or a null pointer return according to the rules
given by Steve.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk