fork download
  1. #include <iostream>
  2.  
  3. template <class T>
  4. class A {
  5. T d;
  6. public:
  7. A(T a) : d(a) {}
  8. template<class U, class V>
  9. friend auto operator*(U& x, V& y) -> decltype(U::d * V::d);
  10. };
  11.  
  12. template<class T, class U>
  13. auto operator*(T& x, U& y) -> decltype(T::d * U::d)
  14. {
  15. return x.d * y.d;
  16. }
  17.  
  18. int main()
  19. {
  20. A<double> a(3.0);
  21. A<int> b(5);
  22.  
  23. std::cout << a * b << std::endl;
  24. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
15