Question 1:

Will this code compile :

Answer:

Yes, because we are storing pointer in boost::any, not the object of Node Class and pointers are always copy constructible.


Question 2:

Will this code compile :

Answer:

Yes, because we are storing object of Node Class and its copy constructor is private. Therefore its object is not copy constructible and cannot be stored in boost::any.

Question 3:

This code will throw exception or not ?

Answer:

Yes, it will throw boost::bad_any_cast exception because types are not matched exactly. It doesn't do the automatic type conversion.

Question 4:

This program will throw a run-time exception or not?

Answer:

Yes, it will throw boost::bad_any_cast exception because boost::any_cast is not able to understand polymorphism.