fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T, typename U>
  5. struct BaseS
  6. {
  7. virtual unsigned int operator()(T t, U u) const;
  8. };
  9.  
  10. template <typename T, typename U>
  11. struct S : BaseS<T,U>
  12. {
  13. unsigned int operator()(T t, U u) const override
  14. {
  15. return 1;
  16. }
  17. };
  18.  
  19. template <typename T>
  20. struct S<T,nullptr_t> : BaseS<T,nullptr_t>
  21. {
  22. virtual bool operator()(T t, nullptr_t u) const override
  23. {
  24. return 2;
  25. }
  26. };
  27.  
  28. class A{};
  29. class B{};
  30.  
  31. int main() {
  32. A a;
  33. B b;
  34.  
  35. cout << S<A*,B*>()(&a,&b) << endl;
  36. cout << S<A*,nullptr_t>()(&a,nullptr) << endl;
  37.  
  38. return 0;
  39. }
  40.  
Compilation error #stdin compilation error #stdout 0s 4368KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct S<A*, std::nullptr_t>’:
prog.cpp:36:26:   required from here
prog.cpp:22:15: error: conflicting return type specified for ‘bool S<T, std::nullptr_t>::operator()(T, std::nullptr_t) const [with T = A*; std::nullptr_t = std::nullptr_t]’
  virtual bool operator()(T t, nullptr_t u) const override
               ^~~~~~~~
prog.cpp:7:23: error:   overriding ‘unsigned int BaseS<T, U>::operator()(T, U) const [with T = A*; U = std::nullptr_t]’
  virtual unsigned int operator()(T t, U u) const;
                       ^~~~~~~~
stdout
Standard output is empty