fork download
  1. #include <iostream>
  2.  
  3. template <typename T1, T1 value>
  4. class Class1
  5. {
  6. public:
  7. template <typename T2>
  8. class Class2
  9. {
  10. public:
  11. explicit Class2(
  12. T2 theValue
  13. ) : myValue(theValue)
  14. {
  15. return;
  16. }
  17.  
  18. template <typename T1Other, T1Other valueOther, typename T2Other>
  19. inline Class2(
  20. typename Class1<T1Other, valueOther>::template Class2<T2Other> const & other
  21. ) {
  22. myValue = other.myValue;
  23. }
  24.  
  25. template <typename T1Other, T1Other valueOther, typename T2Other>
  26. inline bool operator==(
  27. typename Class1<T1Other, valueOther>::template Class2<T2Other> const & other
  28. ) const {
  29. return (myValue == other.myValue);
  30. }
  31.  
  32. private:
  33. T2 myValue;
  34. };
  35.  
  36. Class2<T1> const get() const
  37. {
  38. return Class2<T1>(value);
  39. }
  40. };
  41.  
  42. int main(int argc, char * argv[])
  43. {
  44. Class1<int, 1> c1;
  45. Class1<int, 2> c2;
  46.  
  47. std::cout << (c1.get() == c2.get());
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:47: error: no match for ‘operator==’ in ‘c1.Class1<T1, value>::get [with T1 = int, T1 value = 1]() == c2.Class1<T1, value>::get [with T1 = int, T1 value = 2]()’
stdout
Standard output is empty