fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename Derived>
  5. struct Comparisons
  6. {
  7. };
  8.  
  9.  
  10. template <typename Derived>
  11. bool operator!=(const Comparisons<Derived>& lhs, const Comparisons<Derived>& rhs)
  12. {
  13. const Derived& d1 = static_cast<const Derived&>(lhs);
  14. const Derived& d2 = static_cast<const Derived&>(rhs);
  15.  
  16. return !(d1 == d2);
  17. }
  18.  
  19. int main()
  20. {
  21. Comparisons<int> c1, c2;
  22.  
  23. bool b = c1 != c2;
  24.  
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 4480KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘bool operator!=(const Comparisons<Derived>&, const Comparisons<Derived>&) [with Derived = int]’:
prog.cpp:23:20:   required from here
prog.cpp:13:25: error: invalid static_cast from type ‘const Comparisons<int>’ to type ‘const int&’
     const Derived& d1 = static_cast<const Derived&>(lhs);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:14:25: error: invalid static_cast from type ‘const Comparisons<int>’ to type ‘const int&’
     const Derived& d2 = static_cast<const Derived&>(rhs);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty