universal dynamic_cast<void*> equivalent for polymorphic and not polymorphic types

StackOverflow https://stackoverflow.com/questions/17475736

  •  02-06-2022
  •  | 
  •  

سؤال

I am using dynamic_cast<void*> in a memory manager template to obtain the real address of the object. However dynamic_cast is not allowed for types that are not polymorphic. Is there a more universal way or do I need two versions of the template?

هل كانت مفيدة؟

المحلول

You can use std::is_polymorphic to do a compile-time switch on the two possibilities.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top