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 me, the resulting string s should contain "5" but
instead the exception is thown.
--- 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
> > 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
> > 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)
> Base & b = ...;
> dynamic_cast<Derived &>(b); // throws on error
> Base * p;
> dynamic_cast<Derived *>(p); // returns 0 on error
> Info: http://www.boost.org Unsubscribe:
> Your use of Yahoo! Groups is subject to
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk