#include #include // Compile command // clang++ -I [Path tho boost include directory] test.cpp /* OUTPUT In file included from test.cpp:1: /boost/1.61.0/include/boost/any.hpp:246:16: error: cannot initialize return object of type 'ExampleClass *' with an rvalue of type 'const int **' return operand && operand->type() == boost::typeindex::type_id() ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /boost/1.61.0/include/boost/any.hpp:263:27: note: in instantiation of function template specialization 'boost::any_cast >' requested here nonref * result = any_cast(&operand); ^ test.cpp:27:34: note: in instantiation of function template specialization 'boost::any_cast >' requested here ExampleClass returnedObj = boost::any_cast >(anyObj); */ template class ExampleClass { public: ExampleClass(const T* p) : ptr(p) { } const T** operator &() { return &ptr; } private: const T* ptr; }; int main(int argc, char *argv[]) { ExampleClass obj(new int(10)); boost::any anyObj (obj); ExampleClass returnedObj = boost::any_cast >(anyObj); std::cout << "Returned object is " << *(&returnedObj) << std::endl; return 0; }