Search code examples
c++c++11boostboost-any

Boost::any assign string value


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?


Solution

  • 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