fork download
  1. template<typename Derived>
  2. struct Op
  3. {
  4. template<typename ScalarType>
  5. friend Derived operator* (ScalarType const& Lambda, Derived Rhs)
  6. {
  7. return Rhs *= Lambda;
  8. }
  9. };
  10.  
  11. template<typename T>
  12. struct Foo
  13. {
  14. };
  15.  
  16. template<typename T>
  17. struct Bar : Op<Bar<T> >
  18. {
  19. template<typename U>
  20. Bar operator*= (U)
  21. {
  22. return *this;
  23. }
  24. };
  25.  
  26. template<typename T>
  27. void operator* (Foo<T>, Bar<T>)
  28. {
  29. }
  30.  
  31. int main()
  32. {
  33. Foo<int>() * Bar<int>();
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:33:13: error: ambiguous overload for ‘operator*’ (operand types are ‘Foo<int>’ and ‘Bar<int>’)
  Foo<int>() * Bar<int>();
             ^
prog.cpp:33:13: note: candidates are:
prog.cpp:27:6: note: void operator*(Foo<T>, Bar<T>) [with T = int]
 void operator* (Foo<T>, Bar<T>)
      ^
prog.cpp:5:17: note: Derived operator*(const ScalarType&, Derived) [with ScalarType = Foo<int>; Derived = Bar<int>]
  friend Derived operator* (ScalarType const& Lambda, Derived Rhs)
                 ^
stdout
Standard output is empty