failed coversion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

failed coversion

Boost - Users mailing list

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);

std::cout << boost::any_cast<int>(a) << std::endl;

}

 

This throws the error boost::bad_any_cast: failed conversion using boost::any_cast

 

Thanks

 

 

 

CONFIDENTIALITY NOTICE: This e-mail communication and any attachments may contain proprietary and privileged information for the use of the designated recipients named above. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: failed coversion

Boost - Users mailing list
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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users