2

As explained here, it is possible to perform a compile-time check using templates for whether a function with a given name and signature exists in a class.

Can we verify that a function exists with a given name and signature and that, in addition, it's virtual?

Community
  • 1
  • 1
Brian Bi
  • 111,498
  • 10
  • 176
  • 312
  • I don't think that can be done even at runtime in a portable way. In a non-portable way you could with knowledge of the ABI infer whether the function is virtual or not by storing a pointer to member and looking at the values, but you cannot do some of the required operations at runtime. – David Rodríguez - dribeas Jun 13 '14 at 03:54
  • There's a horribly hackish implementation for unspecified versions of GCC & VC++ [here](http://trac.assembla.com/hippomocks/browser/trunk/HippoMocksTest/is_virtual.cpp?rev=64), if you're desperate enough. Separately, you haven't said explicitly whether you also need the `is_virtual` test to be compile time...? – Tony Delroy Jun 13 '14 at 04:41

0 Answers0