fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. template <class T1, class T2>
  6. auto iloczyn (T1 a, T2 b) -> decltype(a*b) {
  7. cout<<"we've got: "<<typeid(decltype(a)).name()<<" and "<<typeid(decltype(b)).name()<<endl;
  8. return a*b;
  9. }
  10.  
  11. class test {
  12. public:
  13. double val;
  14. test (double val = 0) : val(val) {}
  15. friend test operator * (test a, test b) {
  16. return test(a.val * b.val);
  17. }
  18.  
  19. friend ostream & operator << (ostream &out, test a) {
  20. return out<<a.val;
  21. }
  22. };
  23.  
  24. int main() {
  25. cout<<iloczyn(2.4, test(2))<<endl;
  26. }
  27.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
we've got: d and 4test
4.8