got a bad_any_cast exception

#include <iostream>
#include

only boost::any_cast<double> can work..
"ClassyK_Danad"
#include <iostream> #include
template
boost::any min(const A& a,const B& b) { return a < b ? a : b; } void main() { //got a bad_any_cast exception ! std::cout << boost::any_cast<int>( min( 1, 1.1)) << std::endl; }
how could this happen?

ClassyK_Danad wrote:
#include <iostream> #include
template
boost::any min(const A& a,const B& b) { return a < b ? a : b; } void main() { //got a bad_any_cast exception ! std::cout << boost::any_cast<int>( min( 1, 1.1)) << std::endl; }
Because in your example, min is returning a double, and you're trying to extract an int. -- Eric Niebler Boost Consulting www.boost-consulting.com
participants (3)
-
ClassyK_Danad
-
Eric Niebler
-
Sebastian Redl