How can I get a void * pointer from std :: any I'm trying to do something like this:

... std::any& value = ... ... } else if (value.type() == typeid(std::string)) { ... } else { Parent* obj; If (obj = dynamic_cast<Parent*>(value.getPointer) { obj->something(); ... } else { logE("can't convert value:" << value.type().name(); } } ... 
  • Even if you get void * , you won't be able to pass it to dynamic_cast . In general, the presence of any , typeid and dynamic_cast in one place is very suspicious. - VTT
  • I just need to check whether the value inherits in any class Parent and if successful, execute its method - Alexey Gutnik
  • Maybe you need std::any_cast ? - VTT
  • I have several classes inherited from Parent , I do not want to do a check for each of them. any_cast does not roll. He simply compares type_id and castes in the necessary type. He is not downcast-it? Yes, and it seems like you cannot check type_id for inheritance - Alexey Gutnik

0