2

I have done some looking around and many discussions say "no you can't do that" but it is all evolving fast and I would like to test for this characteristic in a template that does not have access to a pointer to an instance of the object.

rranjik
  • 690
  • 9
  • 21
peterk
  • 5,136
  • 6
  • 33
  • 47
  • possible duplicate: https://stackoverflow.com/questions/22911112/how-to-detect-if-a-method-is-virtual – eerorika Feb 18 '19 at 01:53

1 Answers1

6

With C++11, or later, the std::has_virtual_destructor<T> template provides this information.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • lots of goodies in the traits header. answers a lot of questions :) A corrolary question to this might be is if an object has a virtual destructor do all objects with virtual destructors keep them in the same place in the first vtable so without knowing exactly which base class the pointer came from can one invoke it knowing only the pointer (void *) and whether the template test ( which does know about the base class when it was made was true) The same also might go for invoking any RTTI calls which require a vtable. be present. – peterk Feb 19 '19 at 19:51