fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename Derived>
  5. class Comparisons {
  6. public:
  7. template <typename T>
  8. friend bool operator!=(Comparisons<T> const& a, Comparisons<T> const& b);
  9. };
  10.  
  11. template <typename Derived>
  12. bool operator!=(const Comparisons<Derived>& lhs, const Comparisons<Derived>& rhs)
  13. {
  14. const Derived& d1 = static_cast<const Derived&>(lhs);
  15. const Derived& d2 = static_cast<const Derived&>(rhs);
  16.  
  17. return !(d1 == d2);
  18. }
  19.  
  20. struct Test : Comparisons<Test>
  21. {
  22. friend bool operator==(const Test& t1, const Test& t2);
  23. };
  24.  
  25. bool operator==(const Test& t1, const Test& t2)
  26. {
  27. return true;
  28. }
  29.  
  30. int main()
  31. {
  32. Test t1, t2;
  33.  
  34. bool b = t1 != t2;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 4444KB
stdin
Standard input is empty
stdout
Standard output is empty