Boost::any assign string value

411 Views Asked by At

IDE - Clion, C++11, Boost Version 1.57.0

Why doesn't work this code?

#include "boost/any.hpp"
...
boost::any var = 1550;   // Works
var = "String";  // Error

But works fine this one:

#include "boost/any.hpp"
...
boost::any var = 1550;   // Works
var = string("String");  // Works

Can you explain me reason of this error?

1

There are 1 best solutions below

1
On BEST ANSWER

boost::any — A class whose instances can hold instances of any type that satisfies ValueType requirements. see this: http://www.boost.org/doc/libs/1_55_0/doc/html/boost/any.html