fork download
  1. void baz();
  2. void baz(int);
  3.  
  4. template<typename... Args, typename R>
  5. void bar(R (*)(Args...));
  6.  
  7. template<typename... Args>
  8. void foo()
  9. {
  10. bar<Args...>(baz);
  11. }
  12.  
  13. int main()
  14. {
  15. foo<>(); // Deduces baz()
  16. bar<>(baz); // Ambiguous
  17. foo<int>(); // Deduces baz(int)
  18. bar<int>(baz); // Deduces baz(int)
  19. //foo<void>(); // Ambiguous
  20. //bar<void>(baz); // Ambiguous
  21. }
  22.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:16:11: error: no matching function for call to 'bar(<unresolved overloaded function type>)'
  bar<>(baz);   // Ambiguous
           ^
prog.cpp:5:6: note: candidate: template<class ... Args, class R> void bar(R (*)(Args ...))
 void bar(R (*)(Args...));
      ^
prog.cpp:5:6: note:   template argument deduction/substitution failed:
prog.cpp:16:11: note:   couldn't deduce template parameter 'R'
  bar<>(baz);   // Ambiguous
           ^
stdout
Standard output is empty