Boost logo

Boost Users :

Subject: Re: [Boost-users] failed coversion
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-04-25 13:39:07


AMDG

On 04/25/2018 05:41 AM, Markel, Joseph via Boost-users wrote:
> Is there a way to get the int value by performing division on boost::any variables?
>
> #include <boost/any.hpp>
>
> int main(void) {
> boost::any a = 10;
> std::cout << boost::any_cast<int>(a) << std::endl;
> boost::any s = 2.5; // scaling factor
>
> // scale the value
> a = boost::any_cast<int>(a)/boost::any_cast<float>(s);

It's a `double`, not a `float`.

> std::cout << boost::any_cast<int>(a) << std::endl;
> }
>
> This throws the error boost::bad_any_cast: failed conversion using boost::any_cast
>

In Christ,
Steven Watanabe


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