Boost logo

Boost :

From: Sebastien Marc (sebmarc_at_[hidden])
Date: 2001-10-17 14:24:33


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.

Seb.

--- scleary_at_[hidden] wrote:
> > It brings me with some of the problems i am facing
> > with any. I tested some of the code in the article
> on
> > my plateform (Linux gcc 2.95).
> >
> > boost::any a1 = 5;
> > std::string s;
> > s = boost::any_cast<const char*>(a1);
> >
> > The any_cast throws an exception. That's not
> supposed
> > to happen from what you said in the article.
>
> The *template* parameter doesn't determine whether
> or not any_cast will
> throw; the *function* parameter does:
>
> boost::any a = 5;
> boost::any_cast<float>(a); // throws
> boost::any * p = &a;
> boost::any_cast<float *>(p); // doesn't throw
> (returns 0)
>
> In this sense, any_cast usage is similar to (but not
> *exactly* like)
> dynamic_cast:
>
> Base & b = ...;
> dynamic_cast<Derived &>(b); // throws on error
> Base * p;
> dynamic_cast<Derived *>(p); // returns 0 on error
>
> -Steve
>
> Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk