fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Base {
  5. void foo();
  6. };
  7.  
  8. struct Derived : Base {};
  9.  
  10. template<typename T, T thing>
  11. struct bar {};
  12.  
  13. template<typename T>
  14. void foo() {
  15. bar<void (T::*)(), &T::foo>{};
  16. }
  17.  
  18. int main() {
  19. foo<Base>(); // Works
  20. foo<Derived>(); // Error
  21. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void foo() [with T = Derived]’:
prog.cpp:20:15:   required from here
prog.cpp:15:2: error: could not convert template argument ‘&Base::foo’ to ‘void (Derived::*)()’
  bar<void (T::*)(), &T::foo>{};
  ^~~
stdout
Standard output is empty